Contacts

API is used for. Using and connecting the BESELLER platform API. An example of a request for a list of issued orders for the specified period of time.

API (from English Application Program Interface) is an interface of the interaction between the client's site and the server. Represents a resource that the server opens to work from outside, i.e. The programmer can use them to gain access to the program functionality, library, module. The API makes it possible to work the resources that use the potential and power of the providing site, as well as the launch of additional components to them expanding the possibilities of the Web project.

Benefits:

Types

  • returning. To request a third-party application of a method with specified parameters, the server gives the requested information in a specific format;
  • change. The client calls some server function that enters new information or changes certain settings on it.

API Yandex.Direct

To promote sites, an API is effective.

  1. At its base, developers can create applications that directly interact with the search engine service. Such programs will allow advertisers to flexibly manage large-scale, obtain statistical reports for each of them, accurately predict budgets.
  2. Advertising agencies using the Direct API can view the entire list of their customers, customers - representatives.
  3. If certain phrases used for search engine optimization give a low CTR in contextual advertising, you can automatically shut down on them. On the thematic sites through the API, you can set rates, certain donors can be removed.
  4. Yandex.Direct API has a SOAP interface, Ie provides a wide selection of programming languages \u200b\u200bto create applications. This protocol is supported by Languages \u200b\u200bas Perl, Java,

It's time to talk about such a thing as API Functions in Visual Basic. What are these functions in Visual Basic? Let's figure out, firstly, when you begin to program on Visual Basic, you will immediately realize that using these functions you can write very serious programs, secondly, just a lot cannot be done without using the functions APIs, for example, almost everything connected using the Windows operating system ( for example: find out the username, place on the hard disk and so on).

But in order to start applying these functions in practice, you need to know what they imagine, let's talk first about it.

API theory of Visual Basic functions

API. - This is an Abbrevia Application Programming Interface ( application programming interface). In other words, the API is a set of functions that the operating system itself gives a programmer to use them in their programs. With the API, the programmers easily implement their ideas in practice.

API functions can be called from Visual Basic to perform tasks for which there is not enough standard Visual Basic software code. For example, standard Visual Basic tools do not allow you to turn off the computer or restart it. However, all this can be easily done through access to the corresponding API function.

Almost all the functions that are located in Windows are located inside the DLL ( Dynamic Link Library.). All DLL files are located in the Windows system folder. There are over 1000 API functions that are conventionally divided into four main categories.

  • Working with applications - Start and closing applications, process menu commands, move and change the size of windows;
  • Graphics - image creation;
  • System information - determination of the current disk, the amount of memory, the name of the current user, etc.;
  • Operation with the registry - manipulation with Windows registry.

Application of the functions API in practice

We now proceed directly to the use of these functions in practice. API functions caused to Visual Basic should be first declared. When declared, the name of the DLL and the function, as well as information about the number and type of arguments, is indicated.

DLL procedures are announced by the Declare command in the General Declarations section of the module form or standard module:

Declare Function Name LIB "Library" [([_ variable [, Byval] variable] ...])] AS Type

DLL procedures that are in standard modules are open and may be called from any point of the application. The procedures declared in the form module are closed and the keyword Private should stand before they declare.

The lib section reports where to look for a DLL file containing a function. With reference to the main Windows libraries (user32.dll, kernel32.dll, gdi.dll), the extension is not necessary.

If the path to the file is not specified, directory view starts in the following sequence

  1. Directory containing the EXE file of the program;
  2. Current catalog;
  3. Windows system directory;
  4. Windows directory;
  5. Variable environment of Path.

Here is a small list of standard DLL libraries:

  • advapi.dll - NT Protection, Registry and Other Advanced Services;
  • cOMDLG.DLL - standard dialog boxes;
  • gdi.dll - interface of graphic devices;
  • kernel32.dll - memory, discs, processes, resources;
  • mPR.DLL - network;
  • netaPi32.dll - Network API library;
  • shell32.dll - Windows shell, drag-and-drop, sample of icons;
  • user32.dll - user interface-window, menu, strings, messages;
  • version.dll - control of versions;
  • winmm.dll - multimedia, sound, joysticks, timers;
  • winSpoll.dll - Print Manager.

Most DLL procedures are documented using C and C ++ programming language notation. To successfully convert the API function to the DECLARE command, it is necessary to understand the argument mechanism. Typically, the arguments are transmitted by value. In this case, in front of the name of the argument is the key word byval. If the argument is transmitted by reference, then put byref.

Here is the smallest list of features that are used in Visual Basic:

  • BITBLT - copies the image from one HDC to another;
  • FindWindow - finds a handle window with the specified CAPTION;
  • GetCursorpos - Returns the current position of the mouse cursor (globally);
  • GetDriveType - Returns the type of drive;
  • GetForeGroundWindow - Returns the handle of the active window;
  • SetCursorpos - sets a new mouse cursor position;
  • SetVolumelabel - changes the disk label;
  • SetWindowpos - sets the window position with a specific handle (also using this function can be made so that the window is on top of all;
  • SHELLEXECUTE - Runs an application associated with an extension that has a specified file (can also simply run the specified application);
  • Showcursor - hides or shows mouse cursor on the screen.

Examples of work with the registry

Also when programming on Visual Basic, and in other languages \u200b\u200bthere is a problem when you need to use the Windows registry, but using the functions API it is easy to do, for example:

For reading a string parameter, use the GETREGSTRING function

Example:

Dim Test AS String Test \u003d GetRegString (HKEY_LOCAL_MACHINE, _ "Software \\ Microsoft \\ DirectX", "Version") Form1.caption \u003d Test

To read the DWORD GETREGDWORD parameter

Example:

Dim Test As Long Test \u003d GetRegDWord (HKEY_LOCAL_MACHINE, _ "Software \\ Microsoft \\ Internet Explorer \\ ABOUTURLS", "HOME") Form1.caption \u003d Test

SetRegString is used to record a string parameter

Example:

SetRegString HKEY_LOCAL_MACHINE, _ "SOFTWARE \\ TEST", "MyProgram", "Options"

If the key or parameter was not created, then they will be created if the key or parameter already exists, the new values \u200b\u200bare recorded on top of the old.

SETREGDWORD is used to record the DWORD type parameter

Example:

SetRegdWord HKEY_LOCAL_MACHINE, _ "Software \\ Test", "MyProgram", "555"

To remove the key from the registry uses the DeleteRegKey function

Example:

DELETEREGKEY HKEY_LOCAL_MACHINE, "SOFTWARE", "TEST", TRUE

The second parameter is the parent key
The third parameter is true - if confirmation is required to delete or FALSE - if the confirmation is not required.

DeleteregValue function is used to delete the registry parameter.

Example:

DeleteregValue HKEY_LOCAL_MACHINE, _ "Software \\ Microsoft \\ Internet Explorer \\ abouturls", "Mozilla", False

In fact, the capabilities of the functions API in the Windows operating system are practically limitless. Let's finish on this review of this feature Visual Basic and finally write a small program using the functions APIs.

This program simply displays the message to the screen, insert the following code:

Private Declare Function BeginPath Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function EndPath Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function PathToRegion Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function SetWindowRGN Lib "User32" (Byval Hwnd As Long, Byval Hrgn As Long, Byval Bredraw As Boolean) As Long Private Sub Form_load () Const Text \u003d "You used API" Dim HRGN AS Long Font.name \u003d "Times New Roman" Font.bold \u003d True font.size \u003d 60 width \u003d TextWidth (text) Height \u003d TextHeight (Text) Beginpath HDC Print Text Endpath HDC HRGN \u003d PathToregion (HDC) SetWindowRGN HWND, HRGN, False Move (screen.width - Width) / 2 , (Screen.Height - Height) / 2 End Sub

We used 4 functions here (Beginpath, Endpath, Pathtoregion, SetWindowRGN), which are located in two DLL libraries (GDI32, User32).

That's all while!

We released a new book "Content Marketing on Social Networks: How to sit in the head of subscribers and fall in love with their brand."

The API is an external application programming interface, accessing sites on a specific protocol to obtain information and simplified development of programs related to internal services.

What does the API mean

The simplest analogy of using the API will be the process of working on a calculator for complex computing. Suppose you have a task, you can understand its essence, build equations and graphs, but do not know how to perform arithmetic actions with numbers. Next to you is a calculator who can make these operations with ease. You do not know what is happening inside the computing machine, and it is not necessary to know it. You give information in one form, and get in the other you need for your goals.

For such a principle, any API works. You don't care how the program receives an answer, what path the request is undergoing inside it, how to calculate. You are sure only in one - in response will be issued standardized information about the success of the operation or its error.

The API interface allows you to spend your time, money and effort to buy a new bicycle. You get a working information port receiving and giving the necessary amounts of data for your development.

Pros:

  • Savings on the development of its interface.
  • There is no need to understand the nuances of the question.
  • APIs are developing professionals and take into account all the factors of the internal processes that you may not know about creating your decision.
  • Allows you to communicate with closed through other protocols services.

Minuses:

  • If the target service is updated, the API does not always instantly receive the full functionality.
  • You can not catch the mistakes and do not know how the process is in someone else's code.
  • Not always the API gives the most optimized result in time, as it is intended for processing general cases, not private.

Examples of the API.

API Integration is the process of connecting an application to an external data interface. Working with the API begins with studying documentation and used protocols, and then directly integrate your program to the interface. Consider the most popular services that have their own APIs.

Vkapi.

External interface of interaction between the popular social network VKontakte with clients, as well as with browser and server applications. Allows you to manage community messages, group covers, user pages in the presence of appropriate access keys.

All requests are made to the address. https://api.vk.com/method/

After a slash, the name of the API method used is the name and the Get-parameters of the query are transmitted. The answer also comes to https in JSON format.

Telegram Bot API.

One of the most popular APIs. With it, bots are controlled in Telegram Messenger. After creating a bot via @BotFather and get the necessary access keys, you can start interaction with the internal interface.

Requests are carried out at https://api.telegram.org/bot0000000:Token/

Where, instead of Bot0000000, the unique identifier of your bot is set, and token expresses the secret key.

Requests are sent via HTTPS connection, the method name is indicated via Slash to the main address. The answer comes in JSON format.

Open Weather Map API

Often it is necessary to get information about the weather, not cycling third-party widgets and paid applications. Openweathermap service comes to the rescue with an open and free API. After registering and receiving identification data, you can send requests for weather from the server scripts worldwide. In response to the city ID, the resource returns the most detailed information about current weather and gives a forecast for the near future.

Format Work: HTTP Transmission via API.openweathermap.org/data/2.5/weather?id\u003d, with an indication of the identification number of the desired city. Server response: JSON.

Google Maps API

What could be more pleasant than an interactive world map on the site? Especially if this is not a template insert from Google Maps, and your personal editorial board of a popular map with personal clusters of markers. The card will interact with other scripts on the site, sending information about clicks and coordinates.

Such capabilities offers JavaScript API Google Maps. The module is completely scripted and works on the browser side, so HTTP requests from PHP and the formation of headers on the server side, as it was in other APIs, we do not need.

For example, tagging on the map will look like this:

var Mark \u003d New Google.maps.Marker ((
Position: MYPOS,
Map: Map,
Title: "Hello!"
});

What is needed and how it is useful to use the API

Useful functions are quite a lot.

First aspect

You can establish interactive user interaction with social networks and messengers, use the possibilities of third-party computing systems to display currency exchange rates, weather and other important information.

Using the API, an instant connection to servers of other resources and software solutions is performed, which in ordinary implementation would take weeks of development. The API simplifies life where unique implementation is not needed, and in priority reliability and safety.

Second aspect

If you are the owner of complex computing power, a popular service or data warehouse for open or semi-inspection access, then a good move will raise your own API. What will it give:

  • Big stream of customers.
  • Simplified access to your services for partners.
  • Convenience of statistical analysis of the use of the service.

Third aspect

Almost the same as the second. But without having to implement API for open access. If you have a portal, and you want to create a mobile application on Android / iOS under it, then rewrite the system for a single API is the best solution. The entire data structure is systematized. The site and application will work through single data channels.

By definition from Wikipedia, API is a set of ready-made classes, procedures, functions, structures and constants provided by the application (library, service) for use in external software products. Used by programmers for writing all sorts of applications.

But since much in Wikipedia is not available for understanding by many people, I will try to explain on my fingers what the API is and for which they are usually done, and how to use them.

APIs are completely different, but for example, I chose the situation when we have a chain of stores and only one common database. Imagine that you own a affiliate. A partner works on the following princespa: a person is registered in the affiliate program and receives the store engine. Then he can put this store at his hosting and start working. But all the data at this store is taken from our base, that is, we need to give each partner access to our precious database. Imagine how dangerous it is? After all, we need to open access to the database from out, so that all partner stores could work with it. And what will happen if the access data will fall into the attackers?

Here we will help the API. Instead of giving access to the database, we will simply make an API through which partner stores will receive information. Thus, only our API script will work with the database, and the shops will work with this script.

How it works?
For example, the store sends a request to our API
http://ourapi.com/get_books?limit\u003d20.
And our API understands that he needs to give a list of books consisting of 20 copies, because we have passed the Limit parameter to 20. Our script (API) makes a request to the database, receives a list of books and returns them to the store (in fact, simply displays ) In a specific format. The format in which the API returns information can be completely any, the main thing that our stores would understand it. It can be JSON, serialized array or XML. This is no longer important, the main thing that you understand the principle.

A set of commands that API understands you define yourself. For example, in our case, it could have such commands as receiving a list of books, receiving a list of categories, receiving popular books, receiving new books, etc. Thus, even if the attacker gets the opportunity to contact our API, all that he can do it get a list of books, and this does not put any threats before our database.

I hope I managed to explain what API is on a simple example. If you have questions, ask them in the comments or on the forum and we will gladly help you in their decision.

In order to facilitate the work of his colleagues and provide all programs for Windows universal interface, Microsoft programmers created such a thing as API - "Application Programming Interface".

This is a set of features and procedures that can most often be used by programs: Displays the directory tree, search for files, displaying the standard window with the closing buttons, minimization and deployment to the entire screen and many others. As a result, the developer creating a Windows program should not be thought out and developing special subroutines to display the program window, windows to select the folder and other similar elementary operations - it is enough for it to call it from the Kernel32.dll or user32.dll library, containing functions and procedures API, the function you need, and she will do everything herself for him. There are many such functions and procedures - about 600.

In the MS-DOS operating system, there was no such thing as API, - the one who was taken to write a program for this operating system was obliged to be, from beginning to end, consider and implement ways to issue images on the screen, receiving data from the user, Traveling on the file system, drawing graphics, if such an option was necessary 2. This made the process of developing programs with a convenient user-friendly interface, often the costs of time and effort to create an acceptable graphical program interface exceeded the cost of implementing their own program algorithm, for which it was created. No wonder the so-called "console" applications were very common, that is, programs operating only from the command line, without an interface, - data entry took place in the same command line or was made from the file specified in it, and the output output was in simple text mode.

With the appearance of the Windows operating system, the firmware of programmers for developing the appearance of the program and convenient methods of input and output of the information has increased dramatically, "API functions have been used already in Windows 3.0. Now a programmer, if, for example, wanted to create a text input window or a scroll bar, should only be able to call the display feature of such a window with the parameters you need, just like any other language function on which he wrote his program, and Do not enter the huge volume of code for the sake of creating a program, re-drawing such a window or a strip (conscious in this, that when developing the following program, in which such objects will also be used, it will have to re-develop such a code or try to partially use the old, adapting it to the needs This new program). Therefore, the appearance of the API made a revolutionary breakthrough in programming technology, allowing you to create the necessary programs with the usual handy interface much faster, without taking care of such routine items as programming standard interface objects to enter and output information.

In the Visual Basic for Applications (VBA), many API functions and procedures are called by the program in the interpreter, so use them to display the input and output windows, drawing on the screen of geometric shapes and other simple actions is absolutely no need - their VBA causes As needed, the program on it is enough to use the corresponding functions of this language. However, sometimes there is a need for some actions for which there are no analogues in the built-in VBA functions, or they work is irrational or too slow. For example, the folder selection window with the image of the directory tree (Fig. 5.1) or the file search program (analogue on the VBA functions - the "Application.FileSearch" object is too slow at large quantities of files). For such cases, VBA provides the ability to call the API functions.

Unfortunately, the use of API functions in VBA is not documented in the certificate, as a result of which, to study the methods of their application, it is necessary to either search for books or sources on the Internet for office programming, or analyze the program code in which there are calls for API functions.

In the overwhelming majority of cases, when programming for Office, you can do without using the API, but sometimes only calling the API functions can lead to the achievement of the desired result. Let's say you need to make a call for different macros with a simple jetty button on any Word toolbar and in the case of simultaneously pressing this button and the SHIFT or CONTROL keys. Here is a fragment of the code that makes it:

Declare Function GetasyncKeyState Lib "User32.dll" (Byval Kstate AS Long) AS Integer

GetAsyncKeyState (VBKEYSHIFT OR VBKEYCONTROL)

If GetasyncKeyState (VBKEYSHIFT) THEN

Call Macro1: Exit Sub

Elseif GetAsynckeyState (VBKEYCONTROL) THEN

Call Macro2: Exit Sub

The first line is like a "reservation" of the API function for use in the VBA program. It can be seen that the GETASYNCKEYSTATE function is called from the library (file containing programs intended only for use by other programs) user32.dll, and the key number is transmitted to this function, and it returns an integer (namely - 0 if the key with the corresponding number is not Pressed, and -32767 or 1, if pressed). Any function or procedure called from libraries that are not related to VBA must be so reserved using the Declare command.

The vbkeyshift phrase in the command is the SHIFT key substitute (its value is 16), and VBKEYCONTROL, as it is easy to understand - the CONTROL keys code replacement. The structure of the instructions "IF ... THEN", it seems clear, 3, and if not, look at the VBA Help. Call command in front of the macro name, as you remember, means it starts.

On the Internet there are Russian sites dedicated to API 4. Visit them to learn more about this set of functions.



Did you like the article? Share it