0

Google isn't clear to me on how I can login to the google search console API.

I'm using PHP and CURL.

I passed in for the URL: "sites/example.com/searchAnalytics/query?key=mykey" and I passed in json parameters for the start and end date. mykey was assigned to me after using google cloud to generate one.

When I execute the curl request through PHP, I receive this error:

"API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal."

Oauth2 wouldn't be for me because I'm using an private apache server on my computer to handle the requests.

So I looked into google cloud and I'm able to get a unique ID, a client ID and an email ending in iam.gserviceaccount.com

What values do I feed into CURL when making an authenticated request? I would assume I'd place them in as an HTTP header but google is not clear on this.

Please help.

I tried the API key but the google search API wouldn't allow that as authentication.

6
  • "Oauth2 wouldn't be for me"...think again. use a Service Account: developers.google.com/identity/protocols/oauth2/service-account Commented Oct 20, 2024 at 18:20
  • "What values do I feed into CURL" ...why DIY? github.com/googleapis/google-api-php-client Commented Oct 20, 2024 at 18:20
  • 3rd party package add alot of unnecessary code that I have to cut down to get the information I need. Commented Oct 21, 2024 at 2:41
  • I believe I have made a service account with google cloud but I don't know how to apply the credentials to a curl request. Commented Oct 21, 2024 at 2:43
  • It tells you in the "Preparing to make a delegated call" and "Calling Google APIs" sections of the documentation, if you change the tab to "HTTP/REST". As you can see, submitting the credentials and getting the access token is relatively complex - which is why I said not to make a do-it-yourself solution using cURL. Instead use Google's API client for PHP, at which point it becomes a lot easier. Everything you need to do this task is already available in the documentation. Commented Oct 21, 2024 at 6:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.