Instead of ‘login’ and ‘password’ use your credentials from https://app.dataforseo.com/api-access
<?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-access $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.20230825", "status_code": 20000, "status_message": "Ok.", "time": "0.0957 sec.", "cost": 0, "tasks_count": 1, "tasks_error": 0, "tasks": [ { "id": "11151921-1535-0066-0000-2c32bed229f2", "status_code": 20000, "status_message": "Ok.", "time": "0.0280 sec.", "cost": 0, "result_count": 1, "path": [ "v3", "serp", "google", "search_by_image", "task_get", "advanced", "11151921-1535-0066-0000-2c32bed229f2" ], "data": { "api": "serp", "function": "task_get", "se": "google", "se_type": "search_by_image", "language_code": "en", "location_code": 2840, "image_url": "https://www.shutterstock.com/blog/wp-content/uploads/sites/5/2021/11/shutterstock_721703848.jpg?w=580&h=580&crop=1", "priority": 2, "device": "desktop", "os": "windows" }, "result": [ { "image_url": "https://www.shutterstock.com/blog/wp-content/uploads/sites/5/2021/11/shutterstock_721703848.jpg?w=580&h=580&crop=1", "keyword": null, "type": "search_by_image", "se_domain": "lens.google.com", "location_code": 2840, "language_code": "en", "check_url": "https://lens.google.com/uploadbyurl?url=https%3A%2F%2Fwww.shutterstock.com%2Fblog%2Fwp-content%2Fuploads%2Fsites%2F5%2F2021%2F11%2Fshutterstock_721703848.jpg%3Fw%3D580%26h%3D580%26crop%3D1&hl=en&gl=US&ie=UTF-8&oe=UTF-8&uule=w+CAIQIFISCQs2MuSEtepUEUK33kOSuTsc&ep=gisbubu", "datetime": "2023-11-15 17:21:31 +00:00", "spell": null, "refinement_chips": null, "item_types": [ "images", "organic" ], "se_results_count": 0, "items_count": 61, "items": [ { "type": "images", "rank_group": 1, "rank_absolute": 1, "position": "left", "xpath": null, "title": "Marmalade Art Tropical Flower Wallpaper Mural", "url": null, "items": [ { "type": "images_element", "alt": "Image #1 for Marmalade Art Tropical Flower Wallpaper Mural", "url": "https://www.mural-wallpaper.com/product/wallpaper-murals/nature/flowers-plants/tropical-flower-wallpaper-mural/", "image_url": "https://t2.gstatic.com/images?q=tbn:ANd9GcS0tPJeCrLWv2Dm5C2x32EGaYKv39ciGV-bzKfU_-8mdpTLZdrS" }, { "type": "images_element", "alt": "Image #2 for Marmalade Art Tropical Flower Wallpaper Mural", "url": "https://www.mural-wallpaper.com/product/wallpaper-murals/nature/flowers-plants/tropical-flower-wallpaper-mural/", "image_url": "https://t2.gstatic.com/images?q=tbn:ANd9GcRi0yMpTv31JTW92ZhX89CWE2GsB3XMktAiKeaBhW20YyhM20uU" }, { "type": "images_element", "alt": "Image #3 for Marmalade Art Tropical Flower Wallpaper Mural", "url": "https://www.mural-wallpaper.com/product/wallpaper-murals/art-design/modern/tropical-flora-wall-art/", "image_url": "https://t1.gstatic.com/images?q=tbn:ANd9GcQ_ckV6piXQuE7yR1c2lsEdSEEAad6u0rKgBc92_pvoPATYODab" } ], "related_image_searches": null, "rectangle": null }, { "type": "organic", "rank_group": 1, "rank_absolute": 2, "position": "left", "xpath": null, "domain": "$43.35* • Amazon", "title": "ART.COM Wall Art Prints Colorful Flower on Dark Tropical Foliage Nature Background, Botanical Decor, 36\" x 24\"", "url": "https://www.amazon.com/ART-COM-Colorful-Tropical-Background-Botanical/dp/B0CBL4YQ1L", "cache_url": null, "related_search_url": null, "breadcrumb": null, "website_name": null, "is_image": true, "is_video": false, "is_featured_snippet": false, "is_malicious": false, "is_web_story": false, "description": null, "pre_snippet": null, "extended_snippet": null, "images": [ { "type": "images_element", "alt": null, "url": "https://www.amazon.com/ART-COM-Colorful-Tropical-Background-Botanical/dp/B0CBL4YQ1L", "image_url": "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTMeZt2_Qd0aOrJnJR801KKaE7mVjC5T2VpH1wdbcfHhfB3PU3l" } ], "amp_version": false, "rating": null, "price": null, "highlighted": null, "links": null, "faq": null, "extended_people_also_search": null, "about_this_result": null, "related_result": null, "timestamp": null, "rectangle": null }, { "type": "organic", "rank_group": 2, "rank_absolute": 3, "position": "left", "xpath": null, "domain": "twitter.com", "title": "everpix on X: \"Today is a good day to change the #wallpaper 👌🏻😏😍 #wallpapers #iphonewallpapers #iphonewallpaper #background #backgrounds #bestbackground #bestwallpaper #iphone_wallpaper #iphone_wallpapers #everpix #everpixlive #livewallpaper #contrast #abstractart #abstarct #brightbackground https://t.co/4XYPcKED2G\" / X", "url": "https://twitter.com/everpixapp/status/1097804893534982144", "cache_url": null, "related_search_url": null, "breadcrumb": null, "website_name": null, "is_image": true, "is_video": false, "is_featured_snippet": false, "is_malicious": false, "is_web_story": false, "description": null, "pre_snippet": null, "extended_snippet": null, "images": [ { "type": "images_element", "alt": null, "url": "https://twitter.com/everpixapp/status/1097804893534982144", "image_url": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTOVoJ5uKZZC4TrvK1B9Xr06SdnxZWc8gwTCS4h8Kn7VGC9g6Zs" } ], "amp_version": false, "rating": null, "price": null, "highlighted": null, "links": null, "faq": null, "extended_people_also_search": null, "about_this_result": null, "related_result": null, "timestamp": null, "rectangle": null }, { "type": "organic", "rank_group": 3, "rank_absolute": 4, "position": "left", "xpath": null, "domain": "$10.82* • Redbubble", "title": "Golden Tropical Bloom + Blue-Green Jungle Leaves Art Board Print", "url": "https://www.redbubble.com/i/art-board-print/Golden-Tropical-Bloom-Blue-Green-Jungle-Leaves-by-EscapistDecor/64463975.5E8EA", "cache_url": null, "related_search_url": null, "breadcrumb": null, "website_name": null, "is_image": true, "is_video": false, "is_featured_snippet": false, "is_malicious": false, "is_web_story": false, "description": null, "pre_snippet": null, "extended_snippet": null, "images": [ { "type": "images_element", "alt": null, "url": "https://www.redbubble.com/i/art-board-print/Golden-Tropical-Bloom-Blue-Green-Jungle-Leaves-by-EscapistDecor/64463975.5E8EA", "image_url": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTZbQrafPWoRqWZ9On0nVXTPlzUpCjyqA5-RliIbwjszGnqBMVN" } ], "amp_version": false, "rating": null, "price": null, "highlighted": null, "links": null, "faq": null, "extended_people_also_search": null, "about_this_result": null, "related_result": null, "timestamp": null, "rectangle": null }, { "type": "organic", "rank_group": 4, "rank_absolute": 5, "position": "left", "xpath": null, "domain": "globalgovernanceproject.org", "title": "Inger Andersen, Author at The Global Governance Project", "url": "https://www.globalgovernanceproject.org/author/inger-andersen/", "cache_url": null, "related_search_url": null, "breadcrumb": null, "website_name": null, "is_image": true, "is_video": false, "is_featured_snippet": false, "is_malicious": false, "is_web_story": false, "description": null, "pre_snippet": null, "extended_snippet": null, "images": [ { "type": "images_element", "alt": null, "url": "https://www.globalgovernanceproject.org/author/inger-andersen/", "image_url": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSLR7aWtbhOdJQbYqQ4aBLEFd_0EH6_iR1_axJTXqSzgW74jcnC" } ], "amp_version": false, "rating": null, "price": null, "highlighted": null, "links": null, "faq": null, "extended_people_also_search": null, "about_this_result": null, "related_result": null, "timestamp": null, "rectangle": null } ] } ] } ] }
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.
You can also get all available SERP features and possible extra elements by making a request to the following Sandbox URL:
https://sandbox.dataforseo.com/v3/serp/google/search_by_image/task_get/advanced/00000000-0000-0000-0000-000000000000
The response will include all available items in the Google Search by Image SERP Advanced endpoint with the fields containing dummy data.
You won’t be charged for using Sandbox endpoints.
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 , including_results_for |
refinement_chips |
object | search refinement chips |
type |
string | type of element = ‘refinement_chips’ |
xpath |
string | the XPath of the element |
items |
array | items of the element |
type |
string | type of element = ‘refinement_chips_element’ |
title |
string | title of the element |
url |
string | search URL with refinement parameters |
domain |
string | domain in SERP |
options |
array | further search refinement options |
type |
string | type of element = ‘refinement_chips_option’ |
title |
string | title of the element |
url |
string | search URL with refinement parameters |
domain |
string | domain in SERP |
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 |
related_search_url |
string | URL to a similar search URL to a new search for the same keyword(s) on related sites |
breadcrumb |
string | breadcrumb in SERP |
website_name |
string | name of the website 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 |
is_web_story |
boolean | indicates whether the element is marked as Google web story |
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 |
images |
array | images of the element |
type |
string | type of element = ‘images_element‘ |
alt |
string | alt tag of the image |
url |
string | relevant URL |
image_url |
string | URL of the image the URL leading to the image on the original resource or DataForSEO storage (in case the original source is not available) |
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 |
float | the value of the rating |
votes_count |
integer | the amount of feedback |
rating_max |
integer | the maximum value for a rating_type |
price |
object | pricing details contains the pricing details of the product or service featured in the result |
current |
float | current price indicates the current price of the product or service featured in the result |
regular |
float | regular price indicates the regular price of the product or service with no discounts applied |
max_value |
float | the maximum price the maximum price of the product or service as indicated in the result |
currency |
string | currency of the listed price ISO code of the currency applied to the price |
is_price_range |
boolean | price is provided as a range indicates whether a price is provided in a range |
displayed_price |
string | price string in the result raw price string as provided in the result |
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 |
domain |
string | domain in SERP |
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 |
domain |
string | domain in SERP |
extended_people_also_search |
array | extension of the organic element extension of the organic result containing related search queries Note: extension appears in SERP upon clicking on the result and then bouncing back to search results |
about_this_result |
object | contains information from the ‘About this result’ panel ‘About this result’ panel provides additional context about why Google returned this result for the given query; this feature appears after clicking on the three dots next to most results |
type |
string | type of element = ‘about_this_result_element‘ |
url |
string | result’s URL |
source |
string | source of additional information about the result |
source_info |
string | additional information about the result description of the website from Wikipedia or another additional context |
source_url |
string | URL to full information from the source |
language |
string | the language of the result |
location |
string | location for which the result is relevant |
search_terms |
array | matching search terms that appear in the result |
related_terms |
array | related search terms that appear in the result |
related_result |
array | related result from the same domain related result from the same domain appears as a part of the main result snippet; you can derive the related_result snippets as "type": "organic" results by setting the group_organic_results parameter to false in the POST request |
type |
string | type of element = ‘related_result‘ |
xpath |
string | the XPath of the element |
domain |
string | relevant domain |
title |
string | title of the result in SERP |
url |
string | relevant URL in SERP |
cache_url |
string | cached version of the page |
related_search_url |
string | URL to a similar search URL to a new search for the same keyword(s) on related sites |
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 |
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 |
images |
array | images of the element |
type |
string | type of element = ‘images_element‘ |
alt |
string | alt tag of the image |
url |
string | relevant URL |
image_url |
string | URL of the image the URL leading to the image on the original resource or DataForSEO storage (in case the original source is not available) |
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 |
float | the value of the rating |
votes_count |
integer | the amount of feedback |
rating_max |
integer | the maximum value for a rating_type |
price |
object | pricing details contains the pricing details of the product or service featured in the result |
current |
float | current price indicates the current price of the product or service featured in the result |
regular |
float | regular price indicates the regular price of the product or service with no discounts applied |
max_value |
float | the maximum price the maximum price of the product or service as indicated in the result |
currency |
string | currency of the listed price ISO code of the currency applied to the price |
is_price_range |
boolean | price is provided as a range indicates whether a price is provided in a range |
displayed_price |
string | price string in the result raw price string as provided in the result |
highlighted |
array | words highlighted in bold within the results description |
about_this_result |
object | contains information from the ‘About this result’ panel ‘About this result’ panel provides additional context about why Google returned this result for the given query; this feature appears after clicking on the three dots next to most results |
type |
string | type of element = ‘about_this_result_element‘ |
url |
string | result’s URL |
source |
string | source of additional information about the result |
source_info |
string | additional information about the result description of the website from Wikipedia or another additional context |
source_url |
string | URL to full information from the source |
language |
string | the language of the result |
location |
string | location for which the result is relevant |
search_terms |
array | matching search terms that appear in the result |
related_terms |
array | related search terms that appear in the result |
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 |
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 |