Instead of ‘login’ and ‘password’ use your credentials from https://app.dataforseo.com/api-dashboard
<?php // You can download this file from here https://cdn.dataforseo.com/v3/examples/php/php_RestClient.zip require('RestClient.php'); $api_url = 'https://api.dataforseo.com/'; try { // Instead of 'login' and 'password' use your credentials from https://app.dataforseo.com/api-dashboard $client = new RestClient($api_url, null, 'login', 'password'); } catch (RestClientException $e) { echo "n"; print "HTTP code: {$e->getHttpCode()}n"; print "Error code: {$e->getCode()}n"; print "Message: {$e->getMessage()}n"; print $e->getTraceAsString(); echo "n"; exit(); } try { $result = array(); // #1 - using this method you can get a list of completed tasks // GET /v3/serp/{{low_se_name}}/{{low_se_type}}/tasks_ready // in addition to '{{low_se_name}}' and '{{low_se_type}}' you can also set other search engine and type parameters // the full list of possible parameters is available in documentation $tasks_ready = $client->get('/v3/serp/{{low_se_name}}/{{low_se_type}}/tasks_ready'); // you can find the full list of the response codes here https://docs.dataforseo.com/v3/appendix/errors if (isset($tasks_ready['status_code']) AND $tasks_ready['status_code'] === 20000) { foreach ($tasks_ready['tasks'] as $task) { if (isset($task['result'])) { foreach ($task['result'] as $task_ready) { // #2 - using this method you can get results of each completed task // GET /v3/serp/{{low_se_name}}/{{low_se_type}}/task_get/advanced/$id if (isset($task_ready['endpoint_advanced'])) { $result[] = $client->get($task_ready['endpoint_advanced']); } // #3 - another way to get the task results by id // GET /v3/serp/{{low_se_name}}/{{low_se_type}}/task_get/advanced/$id /* if (isset($task_ready['id'])) { $result[] = $client->get('/v3/serp/{{low_se_name}}/{{low_se_type}}/task_get/advanced/' . $task_ready['id']); } */ } } } } print_r($result); // do something with result } catch (RestClientException $e) { echo "n"; print "HTTP code: {$e->getHttpCode()}n"; print "Error code: {$e->getCode()}n"; print "Message: {$e->getMessage()}n"; print $e->getTraceAsString(); echo "n"; } $client = null; ?>
The above command returns JSON structured like this:
{ "version": "0.1.20220819", "status_code": 20000, "status_message": "Ok.", "time": "0.0847 sec.", "cost": 0, "tasks_count": 1, "tasks_error": 0, "tasks": [ { "id": "09021430-0696-0066-0000-c80786095500", "status_code": 20000, "status_message": "Ok.", "time": "0.0214 sec.", "cost": 0, "result_count": 1, "path": [ "v3", "serp", "google", "local_finder", "task_get", "advanced", "09021430-0696-0066-0000-c80786095500" ], "data": { "api": "serp", "function": "task_get", "se": "google", "se_type": "local_finder", "language_code": "en", "location_code": 2840, "keyword": "local nail services", "min_rating": 4.5, "time_filter": "monday", "device": "desktop", "os": "windows" }, "result": [ { "keyword": "local nail services", "type": "local_finder", "se_domain": "google.com", "location_code": 2840, "language_code": "en", "check_url": "https://www.google.com/search?q=local+nail+services&oq=local+nail+services&tbm=lcl&uule=w+CAIQIFISCQs2MuSEtepUEUK33kOSuTsc&tbs=lrf:!1m4!1u3!2m2!3m1!1e1!1m4!1u2!2m2!2m1!1e1!1m7!1u3!3m4!3m3!5m2!2e1!3e1!4e2!2m1!1e3!2m4!1e2!5m2!2m1!2e9!3sIAE,lf:1,lf_ui:14", "datetime": "2022-09-02 11:30:28 +00:00", "spell": null, "item_types": [ "local_pack" ], "se_results_count": 0, "items_count": 20, "items": [ { "type": "local_pack", "rank_group": 1, "rank_absolute": 1, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[2]", "title": "Liam Nails", "description": "5+ years in business \nMon: 9AM–5PM · +1 443-640-4298 \n\"I’ve been to many nail places in my life and so far this one is the best.\" \n", "domain": "kubiti.wordpress.com", "phone": "+1 443-640-4298", "url": "https://kubiti.wordpress.com/nail-trends/?liam+nails", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.5, "votes_count": 50, "rating_max": 5 }, "cid": "5302726516741959894", "rectangle": null }, { "type": "local_pack", "rank_group": 2, "rank_absolute": 2, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[4]", "title": "Elite Nails", "description": "10+ years in business · Bartlesville, OK, United States \nMon: 9AM–7PM · +1 918-333-9888 \n\"Best nail experience of all time!!!!\" \n", "domain": "kubiti.wordpress.com", "phone": "+1 918-333-9888", "url": "https://kubiti.wordpress.com/nail-trends/?elite+nails", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.7, "votes_count": 353, "rating_max": 5 }, "cid": "17867200233795892980", "rectangle": null }, { "type": "local_pack", "rank_group": 3, "rank_absolute": 3, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[6]", "title": "Kim's Nails", "description": "10+ years in business · Bartlesville, OK, United States \nMon: 10AM–6PM · +1 918-331-9099 \n\"Thought it was a good place to get my nails done.\" \n", "domain": null, "phone": "+1 918-331-9099", "url": null, "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.6, "votes_count": 150, "rating_max": 5 }, "cid": "4930805168864698620", "rectangle": null }, { "type": "local_pack", "rank_group": 4, "rank_absolute": 4, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[8]", "title": "The Nailspot", "description": "3+ years in business · Bartlesville, OK, United States · In Eastland Shopping Center \nMon: 10AM–6PM · +1 918-876-4593 \n\"I love The Nailspot always professional and amazing nail art designs!\" \n", "domain": "www.thenailspot.biz", "phone": "+1 918-876-4593", "url": "http://www.thenailspot.biz/", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.9, "votes_count": 160, "rating_max": 5 }, "cid": "12480940054693735955", "rectangle": null }, { "type": "local_pack", "rank_group": 5, "rank_absolute": 5, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[10]", "title": "KATE Nail Salon", "description": "Owasso, OK, United States · In Reasor's \nMon: 10AM–5PM · +1 918-401-4288 \n\"I absolutely loved my nails from here!!\" \n", "domain": "www.facebook.com", "phone": "+1 918-401-4288", "url": "https://www.facebook.com/katenailok/", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.8, "votes_count": 143, "rating_max": 5 }, "cid": "14192547868485754516", "rectangle": null }, { "type": "local_pack", "rank_group": 6, "rank_absolute": 6, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[12]", "title": "Bellagio Nail Lounge", "description": "Webb City, MO, United States · In Madison Square \nMon: 9AM–7PM · +1 417-717-5026 \n\"This is my new nail place!\" \n", "domain": "bellagionailloungewebbcity.com", "phone": "+1 417-717-5026", "url": "https://bellagionailloungewebbcity.com/", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.9, "votes_count": 120, "rating_max": 5 }, "cid": "15457043881368533418", "rectangle": null }, { "type": "local_pack", "rank_group": 7, "rank_absolute": 7, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[14]", "title": "Humble Bees Nail Spa", "description": "Joplin, MO, United States · In Crown Plaza \nMon: 9AM–7PM · +1 417-553-0144 \n\"The nail technicians are wonderful, plus I love the atmosphere!\" \n", "domain": "www.humblebeesnail.com", "phone": "+1 417-553-0144", "url": "https://www.humblebeesnail.com/", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.8, "votes_count": 688, "rating_max": 5 }, "cid": "1529620928837849201", "rectangle": null }, { "type": "local_pack", "rank_group": 8, "rank_absolute": 8, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[16]", "title": "LEE NAILS SPA", "description": "3+ years in business · Owasso, OK, United States \nMon: 9:30AM–7PM · +1 918-516-2018 \n\"I will 100% continue to come here for my nails.\" \n", "domain": "leenailsspaowasso.com", "phone": "+1 918-516-2018", "url": "https://leenailsspaowasso.com/", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.8, "votes_count": 150, "rating_max": 5 }, "cid": "2509344316202225659", "rectangle": null }, { "type": "local_pack", "rank_group": 9, "rank_absolute": 9, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[18]", "title": "Lush Nail Bar", "description": "Broken Arrow, OK, United States \nMon: 9AM–7PM · +1 918-994-6399 \nOffer: We're open today! \n", "domain": "vnailweb.com", "phone": "+1 918-994-6399", "url": "https://vnailweb.com/lush-nail-bar-nail-salon-near-me-broken-arrow-ok-74012/", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.6, "votes_count": 364, "rating_max": 5 }, "cid": "2866933479710100417", "rectangle": null }, { "type": "local_pack", "rank_group": 10, "rank_absolute": 10, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[20]", "title": "Nail Tech", "description": "10+ years in business · Joplin, MO, United States · In Southside Shopping Center \nMon: 9AM–7PM · +1 417-206-9499 \n\"Hands down favorite nail salon!\" \n", "domain": "kubiti.wordpress.com", "phone": "+1 417-206-9499", "url": "https://kubiti.wordpress.com/nail-trends/?nail+tech", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.6, "votes_count": 64, "rating_max": 5 }, "cid": "2079100440959176574", "rectangle": null }, { "type": "local_pack", "rank_group": 11, "rank_absolute": 11, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[22]", "title": "Reflections Salon & Spa", "description": "7+ years in business · Independence, KS, United States \nMon: 10AM–5:30PM · +1 620-331-0925 \n\"One nail had to be tipped because it had broken off short.\" \n", "domain": "site2trust.com", "phone": "+1 620-331-0925", "url": "https://site2trust.com/browse-category/beauty-and-personal-care", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.5, "votes_count": 38, "rating_max": 5 }, "cid": "1852682742792509771", "rectangle": null }, { "type": "local_pack", "rank_group": 12, "rank_absolute": 12, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[24]", "title": "VOCO Nails", "description": "7+ years in business · Broken Arrow, OK, United States · In Quail Run \nMon: 9:30AM–7PM · +1 918-679-0246 \n\"Best nail experience I’ve ever had.\" \n", "domain": "www.facebook.com", "phone": "+1 918-679-0246", "url": "https://www.facebook.com/HeatherLeTul", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.5, "votes_count": 53, "rating_max": 5 }, "cid": "5952138210777509341", "rectangle": null }, { "type": "local_pack", "rank_group": 13, "rank_absolute": 13, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[26]", "title": "Mon Amie Nails and Spa", "description": "Tulsa, OK, United States \nMon: 9AM–7PM · +1 918-584-8176 \n\"Good for the nails, good for the soul!\" \n", "domain": "www.monamiespa.com", "phone": "+1 918-584-8176", "url": "https://www.monamiespa.com/", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.9, "votes_count": 469, "rating_max": 5 }, "cid": "4171968824820092118", "rectangle": null }, { "type": "local_pack", "rank_group": 14, "rank_absolute": 14, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[28]", "title": "Magic Nails", "description": "10+ years in business · Bentonville, AR, United States \nMon: 10AM–6PM · +1 479-273-0008 \n\"I absolutely love going here to get my nails done!\" \n", "domain": "m.facebook.com", "phone": "+1 479-273-0008", "url": "https://m.facebook.com/Magic-Nails-105426367618355/?ref=bookmarks", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.7, "votes_count": 70, "rating_max": 5 }, "cid": "6737696406619835671", "rectangle": null }, { "type": "local_pack", "rank_group": 15, "rank_absolute": 15, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[30]", "title": "Xtreme Nails", "description": "10+ years in business · Broken Arrow, OK, United States \nMon: 10AM–7PM · +1 918-615-3434 \nTakeout · No delivery \n", "domain": "www.facebook.com", "phone": "+1 918-615-3434", "url": "http://www.facebook.com/xtremenailsBAOK/", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.5, "votes_count": 161, "rating_max": 5 }, "cid": "17518792514080419735", "rectangle": null }, { "type": "local_pack", "rank_group": 16, "rank_absolute": 16, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[32]", "title": "Bally's Nails", "description": "10+ years in business · Tulsa, OK, United States \nMon: 10AM–7PM · +1 918-742-4340 \n\"I really want to thank you so much, Natalie, for fixing my nail.\" \n", "domain": "ballynailstulsa.com", "phone": "+1 918-742-4340", "url": "https://ballynailstulsa.com/", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.5, "votes_count": 188, "rating_max": 5 }, "cid": "10346393581796099215", "rectangle": null }, { "type": "local_pack", "rank_group": 17, "rank_absolute": 17, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[34]", "title": "Nail Focus", "description": "5+ years in business · Claremore, OK, United States · In The Market \nMon: 10AM–7PM · +1 918-341-7900 \n\"My nails are not easy to do because of my short wide nail beds.\" \n", "domain": "kubiti.wordpress.com", "phone": "+1 918-341-7900", "url": "https://kubiti.wordpress.com/nail-trends/?nail+focus", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.5, "votes_count": 77, "rating_max": 5 }, "cid": "6191133628297990316", "rectangle": null }, { "type": "local_pack", "rank_group": 18, "rank_absolute": 18, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[36]", "title": "LV Nails", "description": "10+ years in business · Broken Arrow, OK, United States · In Arrow Village Shopping Center \nMon: 9:30AM–7:30PM · +1 918-251-8777 \n\"When I would go to other places my nails would always chip or crack.\" \n", "domain": "m.facebook.com", "phone": "+1 918-251-8777", "url": "https://m.facebook.com/profile.php?id=100063803643102&fref=nf&_rdr", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.5, "votes_count": 91, "rating_max": 5 }, "cid": "13974777229434172959", "rectangle": null }, { "type": "local_pack", "rank_group": 19, "rank_absolute": 19, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[38]", "title": "Nail Status", "description": "Grove, OK, United States \nMon: 9AM–6PM · +1 918-787-9940 \n\"My favorite nail place\" \n", "domain": null, "phone": "+1 918-787-9940", "url": null, "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.7, "votes_count": 48, "rating_max": 5 }, "cid": "2325380371126469804", "rectangle": null }, { "type": "local_pack", "rank_group": 20, "rank_absolute": 20, "position": "right", "xpath": "/html[1]/body[1]/div[6]/div[1]/div[9]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[40]", "title": "Quincy nail bar", "description": "Joplin, MO, United States \nMon: 10AM–7:30PM · +1 417-553-0652 \n\"Also the gel nails are great\" \n", "domain": "kubiti.wordpress.com", "phone": "+1 417-553-0652", "url": "https://kubiti.wordpress.com/nail-trends/?quincy+nail+bar", "is_paid": false, "rating": { "rating_type": "Max5", "value": 4.5, "votes_count": 127, "rating_max": 5 }, "cid": "2417129273791838327", "rectangle": null } ] } ] } ] }
Description of the fields for sending a request:
Field name | Type | Description |
---|---|---|
id |
string | task identifier a universally unique identifier (UUID) unique task identifier in our system you will be able to use it within 30 days to request the results of the task at any time |
As a response of the API server, you will receive JSON-encoded data containing a tasks
array with the information specific to the set tasks.
Description of the fields in the results array:
Field name | Type | Description |
---|---|---|
version |
string | the current version of the API |
status_code |
integer | general status code you can find the full list of the response codes here Note: we strongly recommend designing a necessary system for handling related exceptional or error conditions |
status_message |
string | general informational message you can find the full list of general informational messages here |
time |
string | execution time, seconds |
cost |
float | total tasks cost, USD |
tasks_count |
integer | the number of tasks in the tasks array |
tasks_error |
integer | the number of tasks in the tasks array returned with an error |
tasks |
array | array of tasks |
id |
string | task identifier unique task identifier in our system in the UUID format |
status_code |
integer | status code of the task generated by DataForSEO; can be within the following range: 10000-60000 you can find the full list of the response codes here |
status_message |
string | informational message of the task you can find the full list of general informational messages here |
time |
string | execution time, seconds |
cost |
float | cost of the task, USD |
result_count |
integer | number of elements in the result array |
path |
array | URL path |
data |
object | contains the same parameters that you specified in the POST request |
result |
array | array of results |
keyword |
string | keyword received in a POST array the keyword is returned with decoded %## (plus symbol ‘+’ will be decoded to a space character) |
type |
string | search engine type in a POST array |
se_domain |
string | search engine domain in a POST array |
location_code |
integer | location code in a POST array |
language_code |
string | language code in a POST array |
check_url |
string | direct URL to search engine results you can use it to make sure that we provided exact results |
datetime |
string | date and time when the result was received in the UTC format: “yyyy-mm-dd hh-mm-ss +00:00” example: 2019-11-15 12:57:46 +00:00 |
spell |
object | autocorrection of the search engine if the search engine provided results for a keyword that was corrected, we will specify the keyword corrected by the search engine and the type of autocorrection |
keyword |
string | keyword obtained as a result of search engine autocorrection the results will be provided for the corrected keyword |
type |
string | type of autocorrection possible values: did_you_mean , showing_results_for , no_results_found_for , including_results_for |
item_types |
array | types of search results in SERP contains types of search results ( items ) found in SERP.possible item types: local_pack |
se_results_count |
integer | total number of results in SERP |
items_count |
integer | the number of results returned in the items array |
items |
array | elements of search results found in SERP |
‘Local Pack’ SERP element | ||
type |
string | type of element = ‘local_pack’ |
rank_group |
integer | group rank in SERP position within a group of elements with identical type valuespositions of elements with different type values are omitted from rank_group |
rank_absolute |
integer | absolute rank in SERP absolute position among all the elements in SERP |
position |
string | the alignment of the element in SERP can take the following values: left , right |
xpath |
string | the XPath of the element |
title |
string | title of the result in SERP |
description |
string | description of the results element in SERP |
domain |
string | domain in SERP |
phone |
string | phone number |
url |
string | relevant URL |
is_paid |
boolean | indicates whether the element is an ad |
rating |
object | the item’s rating the popularity rate based on reviews and displayed in SERP |
rating_type |
string | the type of rating here you can find the following elements: Max5 , Percents , CustomMax |
value |
float | the value of the rating |
votes_count |
integer | the amount of feedback |
rating_max |
integer | the maximum value for a rating_type |
cid |
string | google-defined client id unique id of a local establishment; can be used with Google Reviews API to get a full list of reviews |
rectangle |
object | rectangle parameters contains cartesian coordinates and pixel dimensions of the result’s snippet in SERP in this case, will equal null |