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/'; // Instead of 'login' and 'password' use your credentials from https://app.dataforseo.com/api-dashboard $client = new RestClient($api_url, null, 'login', 'password'); try { $result = array(); // #1 - using this method you can get a list of completed tasks // GET /v3/serp/google/search_by_image/tasks_ready // in addition to 'google' and 'search_by_image' 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/google/search_by_image/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/google/search_by_image/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/google/search_by_image/task_get/advanced/$id /* if (isset($task_ready['id'])) { $result[] = $client->get('/v3/serp/google/search_by_image/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.20200923", "status_code": 20000, "status_message": "Ok.", "time": "0.1140 sec.", "cost": 0, "tasks_count": 1, "tasks_error": 0, "tasks": [ { "id": "10071436-1535-0066-0000-de2760cc8fc4", "status_code": 20000, "status_message": "Ok.", "time": "0.0241 sec.", "cost": 0, "result_count": 1, "path": [ "v3", "serp", "google", "search_by_image", "task_get", "advanced", "10071436-1535-0066-0000-de2760cc8fc4" ], "data": { "api": "serp", "function": "task_get", "se": "google", "se_type": "search_by_image", "language_code": "en", "location_code": "2840", "image_url": "https://d.wattpad.com/story_parts/947637531/images/1631a35e92e45956824754475017.jpg", "calculate_rectangles": true, "device": "desktop", "os": "windows" }, "result": [ { "image_url": "https://d.wattpad.com/story_parts/947637531/images/1631a35e92e45956824754475017.jpg", "keyword": "new york city", "type": "search_by_image", "se_domain": "google.com", "location_code": 2840, "language_code": "en", "check_url": "https://www.google.com/searchbyimage?image_url=https%3A%2F%2Fd.wattpad.com%2Fstory_parts%2F947637531%2Fimages%2F1631a35e92e45956824754475017.jpg&hl=en&gl=US&gws_rd=cr&ie=UTF-8&oe=UTF-8&uule=w+CAIQIFISCQs2MuSEtepUEUK33kOSuTsc&num=100", "datetime": "2020-10-07 11:37:38 +00:00", "spell": null, "item_types": [ "organic", "images" ], "se_results_count": 245, "items_count": 9, "items": [ { "type": "organic", "rank_group": 1, "rank_absolute": 1, "position": "left", "xpath": "/html[1]/body[1]/div[7]/div[2]/div[10]/div[1]/div[2]/div[1]/div[2]/div[2]/div[1]/div[1]/div[1]", "domain": "en.wikipedia.org", "title": "New York City - Wikipedia", "url": "https://en.wikipedia.org/wiki/New_York_City", "cache_url": null, "breadcrumb": "en.wikipedia.org › wiki › New_York_City", "is_image": false, "is_video": false, "is_featured_snippet": false, "is_malicious": false, "description": "New York City, often called simply New York and abbreviated as NYC, is the most populous city in the United States. With an estimated 2019 population of ...", "pre_snippet": null, "extended_snippet": null, "amp_version": false, "rating": null, "highlighted": [ "New York City", "NYC" ], "links": null, "faq": null, "timestamp": null, "rectangle": { "x": 180, "y": 340, "width": 600, "height": 97 } }, { "type": "images", "rank_group": 1, "rank_absolute": 3, "position": "left", "xpath": "/html[1]/body[1]/div[7]/div[1]/div[10]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[2]/div[1]/div[2]", "title": "Visually similar images", "url": "https://www.google.com/search?num=100&hl=en&gl=US&tbs=simg:CAESYAmsZJ7LFuxZbhpVCxCwjKcIGjkKNwgEEhNDrySXFY4Z9hjnOLIuuhLuJJYBGhomn59ppzMD0cv8-RjBsu-9a0VMFuybLJ-PlyAFMAQMCxCOrv4IGgoKCAgBEgRD9ShfDA&q=new+york+city&tbm=isch&sa=X&ved=2ahUKEwj0pMvXmfr0AhU0F7kGHdRDCzIQjJkEegQIAxAC", "items": [ { "type": "images_element", "alt": "Image result", "url": "https://www.pdfprof.com/PDF_Image.php?idt=17174&t=27", "image_url": "https://api.dataforseo.com/cdn/i/12231707-1535-0066-0000-9a7573e50bce:0" }, { "type": "images_element", "alt": "Image result", "url": "https://www.zillow.com/new-york-ny/billionaires-row_att/", "image_url": "https://api.dataforseo.com/cdn/i/12231707-1535-0066-0000-9a7573e50bce:1" }, { "type": "images_element", "alt": "Image result", "url": "https://www.kayak.com/flight-routes/Miami-MIA/New-York-NYC", "image_url": "https://api.dataforseo.com/cdn/i/12231707-1535-0066-0000-9a7573e50bce:2" }, { "type": "images_element", "alt": "Image result", "url": "https://www.freepik.com/free-photo/high-angle-shot-city-buildings-new-york-manhattan_11541116.htm", "image_url": "https://api.dataforseo.com/cdn/i/12231707-1535-0066-0000-9a7573e50bce:3" }, { "type": "images_element", "alt": "Image result", "url": "https://www.kayak.co.uk/Cheap-New-York-Car-Hire.15830.cars.ksp", "image_url": "https://api.dataforseo.com/cdn/i/12231707-1535-0066-0000-9a7573e50bce:4" }, { "type": "images_element", "alt": "Image result", "url": "https://www.tkc.edu/academics/nyc-semester/", "image_url": "https://api.dataforseo.com/cdn/i/12231707-1535-0066-0000-9a7573e50bce:5" }, { "type": "images_element", "alt": "Image result", "url": "https://en.wikipedia.org/wiki/Economy_of_New_York_City", "image_url": "https://api.dataforseo.com/cdn/i/12231707-1535-0066-0000-9a7573e50bce:6" }, { "type": "images_element", "alt": "Image result", "url": "https://www.nationalgeographic.com/travel/destination/new-york-city", "image_url": "https://api.dataforseo.com/cdn/i/12231707-1535-0066-0000-9a7573e50bce:7" }, { "type": "images_element", "alt": "Image result", "url": "https://news.sky.com/story/new-york-city-mayor-race-plunged-into-chaos-as-officials-admit-counting-test-votes-12345406", "image_url": "https://api.dataforseo.com/cdn/i/12231707-1535-0066-0000-9a7573e50bce:8" }, { "type": "images_element", "alt": "Image result", "url": "https://www.cleveland.com/travel/2021/11/return-to-new-york-city-tourists-can-expect-fewer-crowds-cheaper-prices-omnipresent-vaccine-cards.html", "image_url": "https://api.dataforseo.com/cdn/i/12231707-1535-0066-0000-9a7573e50bce:9" }, { "type": "images_element", "alt": "Image result", "url": "https://www.cnn.com/2021/04/29/politics/new-york-city-coronavirus-restrictions-lifted-de-blasio/index.html", "image_url": "https://api.dataforseo.com/cdn/i/12231707-1535-0066-0000-9a7573e50bce:10" }, { "type": "images_element", "alt": "Image result", "url": "https://www.tripsavvy.com/top-nyc-tourist-attractions-and-landmarks-1612759", "image_url": "https://api.dataforseo.com/cdn/i/12231707-1535-0066-0000-9a7573e50bce:11" } ], "related_image_searches": null, "rectangle": { "x": 180, "y": 590, "width": 652, "height": 424 } }, { "type": "organic", "rank_group": 3, "rank_absolute": 4, "position": "left", "xpath": "/html[1]/body[1]/div[7]/div[2]/div[10]/div[1]/div[2]/div[1]/div[2]/div[2]/div[1]/div[1]/div[5]", "domain": "www.lonelyplanet.com", "title": "Experience New York City | New York, USA, North America ...", "url": "https://www.lonelyplanet.com/usa/new-york-city", "cache_url": null, "breadcrumb": "www.lonelyplanet.com › ... › USA › New York", "is_image": true, "is_video": false, "is_featured_snippet": false, "is_malicious": false, "description": "1280 × 520 — New York City's best sights and local secrets from travel experts you can trust. | Epicenter of the arts. Architectural darling. Dining and shopping capital.", "pre_snippet": null, "extended_snippet": null, "amp_version": false, "rating": null, "highlighted": [ "New York City's" ], "links": null, "faq": null, "timestamp": null, "rectangle": { "x": 180, "y": 1090, "width": 600, "height": 97 } } ] } ] } ] }
Description of the fields for sending a request:
Field name | Type | Description |
---|---|---|
id |
string | task identifier unique task identifier in our system in the UUID format 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 |
image_url |
string | URL specified in a POST array |
keyword |
string | keyword Google associated with the specified image |
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 accurate 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 |
item_types |
array | types of search results in SERP contains types of search results ( items ) found in SERP.possible item types: organic ,images |
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 |
‘organic’ element in SERP![]() |
||
type |
string | type of element = ‘organic’ |
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 |
domain |
string | domain in SERP |
title |
string | title of the result in SERP |
url |
string | relevant URL in SERP |
cache_url |
string | cached version of the page |
breadcrumb |
string | breadcrumb in SERP |
is_image |
boolean | indicates whether the element contains an image |
is_video |
boolean | indicates whether the element contains a video |
is_featured_snippet |
boolean | indicates whether the element is a featured_snippet |
is_malicious |
boolean | indicates whether the element is marked as malicious |
description |
string | description of the results element in SERP |
pre_snippet |
string | includes additional information appended before the result description in SERP |
extended_snippet |
string | includes additional information appended after the result description in SERP |
amp_version |
boolean | Accelerated Mobile Pages indicates whether an item has the Accelerated Mobile Page (AMP) version |
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 |
integer | the value of the rating |
votes_count |
integer | the amount of feedback |
rating_max |
integer | the maximum value for a rating_type |
highlighted |
array | words highlighted in bold within the results description |
links |
array | sitelinks the links shown below some of Google’s search results if there are none, equals null |
type |
string | type of element = ‘link_element‘ |
title |
string | title of the result in SERP |
description |
string | description of the results element in SERP |
url |
string | sitelink URL |
faq |
object | frequently asked questions questions and answers extension shown below some of Google’s search results if there are none, equals null |
type |
string | type of element = ‘faq_box‘ |
items |
array | items featured in the faq_box |
type |
string | type of element = ‘faq_box_element‘ |
title |
string | question related to the result |
description |
string | answer provided in the drop-down block |
links |
array | links featured in the faq_box_element |
type |
string | type of element = ‘link_element‘ |
title |
string | link anchor text |
url |
string | link URL |
timestamp |
string | date and time when the result was published in the UTC format: “yyyy-mm-dd hh-mm-ss +00:00” example: 2019-11-15 12:57:46 +00:00 |
rectangle |
object | rectangle parameters contains cartesian coordinates and pixel dimensions of the result’s snippet in SERP equals null if calculate_rectangles in the POST request is not set to true |
x |
float | x-axis coordinate x-axis coordinate of the top-left corner of the result’s snippet, where top-left corner of the screen is the origin |
y |
float | y-axis coordinate y-axis coordinate of the top-left corner of the result’s snippet, where top-left corner of the screen is the origin |
width |
float | width of the element in pixels |
height |
float | height of the element in pixels |
‘images’ element in SERP![]() |
||
type |
string | type of element = ‘images’ |
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 |
url |
string | relevant URL |
items |
array | additional items present in the element if there are none, equals null |
type |
string | type of element = ‘images_element‘ |
alt |
string | alt tag of the image |
url |
string | URL of the image resource the URL leading to the resource where the image is posted |
image_url |
string | URL to the compressed image the URL leading to the image thumbnail |
related_image_searches |
array | contains keywords and images related to the specified search term if there are none, equals null |
type |
string | type of element = ‘related_image_searches_element‘ |
title |
string | title of the element indicates keyword that may be used with the specified term to refine image search |
alt |
string | alt tag of the featured image |
url |
string | original URL of the featured image the URL leading to the image on the original resource |
image_url |
string | URL to the compressed featured image the URL leading to the image on DataForSEO storage |
rectangle |
object | rectangle parameters contains cartesian coordinates and pixel dimensions of the result’s snippet in SERP equals null if calculate_rectangles in the POST request is not set to true |
x |
float | x-axis coordinate x-axis coordinate of the top-left corner of the result’s snippet, where top-left corner of the screen is the origin |
y |
float | y-axis coordinate y-axis coordinate of the top-left corner of the result’s snippet, where top-left corner of the screen is the origin |
width |
float | width of the element in pixels |
height |
float | height of the element in pixels |