Skip to content

georgesvash/CSharpClient

 
 

Repository files navigation

OVERVIEW

There is a C# client to call DataForSeo API.

DataForSEO API uses REST technology for interchanging data between your application and our service. The data exchange is made through the widely used HTTP protocol, which allows applying our API to almost all programming languages.

Client contains 12 sections (aka API):

API Contains 2 types of requests:

  1. Live (Simple HTTP request/response message)
  2. Task-Based (Where you need to send a 'Task' entity to execute, waiting until the 'Task' status is ready and getting the 'Task' result in a special endpoint. Usually, it represents in 3 endpoints 'TaskPost', 'TaskReady', and 'TaskGet')

For more details - please follow here

YAML Spec

Our API description is based on openAPI syntax in YAML format. The YAML file attached to the project with the name here

Code generation

Code generated with using NSwag lib

Documentation

The documentation for code objects, formatted in Markdown (.md) is available here. Offical documentation for DataForSeo API is avaliable here.

install package from nuget.org

dotnet add package DataForSeo.Client 

Examples of usage

Example of live request

var dfsClient = new DataForSeoClient("USERNAME", "PASSWORD");
      var result = await dfsClient.SerpApi.GoogleOrganicLiveAdvancedAsync(new List<SerpTaskRequestInfo>()
      {
          new()
          {
              LanguageCode = "en",
              LocationCode = 2840,
              Keyword = "albert einstein",
              Priority = 2,
          }
      });

Example of Task-based request

var dfsClient = new DataForSeoClient("USERNAME", "PASSWORD");
var result = await dfsClient.SerpApi.GoogleOrganicTaskPostAsync(new List<SerpTaskRequestInfo>()
{
    new()
    {
        LanguageCode = "en",
        LocationCode = 2840,
        Keyword = "albert einstein",
        Priority = 2,
    }
});

var sw = Stopwatch.StartNew();

var id = result.Tasks.First().Id;
while (!await GoogleOrganicTaskReady(id) && sw.Elapsed < TimeSpan.FromMinutes(1))
    await Task.Delay(1_000);

var taskGetResult = await dfsClient.SerpApi.GoogleOrganicTaskGetAdvancedAsync(id);

async Task<bool> GoogleOrganicTaskReady(string id)
{
    var result = await  dfsClient.SerpApi.GoogleOrganicTasksReadyAsync();
    return result.Tasks?.Any(x => x.Result?.Any(xx => xx.Id == id) ?? false) ?? false;
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%