Google Suggest Query Using Curl

Using CURL with Google

Use a GET request instead of a POST request. That is, get rid of

curl_setopt($ch, CURLOPT_POST, true);

Or even better, use their well defined search API instead of screen-scraping.

Get request to Google Search

You can load it in the browser and then scrape results via Javascript.

Or you can use Google API, but seems that it requires payment if you will request it more then 100 times per day.

querying Google.Groups

I haven't worked directly with /ServiceLoginAuth, but from my work with /Login and /AddSession, my guess is that you are missing some hidden form values used to secure the login.

In this case, I would look at the hidden #gaia_universallogin form and attempt to replicate the login flow:

  1. Hit https://www.google.com/accounts/ServiceLoginAuth. It returns you a form with id gaia_universallogin that contains login tokens.
  2. Set the POST data to reflect each header of that form, as well as the Email and Passwd fields (like you are doing now)
  3. Set the continue parameter (if you like) and POST the request. You will either be returned a google settings page or the continue page if you've logged in, or a page with another login form if you aren't.

In this case, I suspect you are missing the dsh token.

How to use curl to get a GET request exactly same as using Chrome?

If you need to set the user header string in the curl request, you can use the -H option to set user agent like:

curl -H "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36" http://stackoverflow.com/questions/28760694/how-to-use-curl-to-get-a-get-request-exactly-same-as-using-chrome

Updated user-agent form newest Chrome at 02-22-2021


Using a proxy tool like Charles Proxy really helps make short work of something like what you are asking. Here is what I do, using this SO page as an example (as of July 2015 using Charles version 3.10):

  1. Get Charles Proxy running
  2. Make web request using browser
  3. Find desired request in Charles Proxy
  4. Right click on request in Charles Proxy
  5. Select 'Copy cURL Request'

Copy cURL Request example in Charles 3.10.2

You now have a cURL request you can run in a terminal that will mirror the request your browser made. Here is what my request to this page looked like (with the cookie header removed):

curl -H "Host: stackoverflow.com" -H "Cache-Control: max-age=0" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36" -H "HTTPS: 1" -H "DNT: 1" -H "Referer: https://www.google.com/" -H "Accept-Language: en-US,en;q=0.8,en-GB;q=0.6,es;q=0.4" -H "If-Modified-Since: Thu, 23 Jul 2015 20:31:28 GMT" --compressed http://stackoverflow.com/questions/28760694/how-to-use-curl-to-get-a-get-request-exactly-same-as-using-chrome

Google Drive API creates a File instead of a Folder using curl call

  • You want to create new folder in your Google Drive using a curl command.
  • You have already been able to use Drive API.

    • Your access token can be used for the POST method.

If my understanding is correct, how about this modification?

Modification points:

  • When new folder is created, you can use https://www.googleapis.com/drive/v3/files as the endpoint.
  • When Drive API v3 is used, the folder name can be set by the property of name.

When above modification is reflected to your curl command, it becomes as follows.

Modified curl command:

curl \
-H 'Authorization: Bearer ### your access token ###' \
-H 'Content-Type: application/json' \
-d '{"name": "mb", "mimeType": "application/vnd.google-apps.folder"}' \
https://www.googleapis.com/drive/v3/files

Reference:

  • Files: create

If I misunderstood your question and this was not the result you want, I apologize.



Related Topics



Leave a reply



Submit