0

I have been trying to use the google rest api for google webmaster integration into my system.

After going through it's documentation i am able to configure all it's OAuth keys and client id so when i use the Api Explorer i am getting the required reponse there.

There itself i get some url like this :

https://www.googleapis.com/webmasters/v3/sites/https%3A%2F%2Fwww.abcd.in?key={YOUR_API_KEY}

I am providing client secret key in the YOUR_API_KEY but when i hit the url in browser i get this error :

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

PS: i didnt't get any api key while generating the OAuth key (if you think i shud have used any kind of API key here ).

Can anyone help ?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Aquarius
  • 421
  • 5
  • 11

1 Answers1

0

You need to go to Google developer console and register your own project. Make sure to enable the webmasters api and create oauth2 credentials.

The Key parameter only works for public data. Webmaster tools data is private user data so you will be using an access token and not a public api key

https://www.googleapis.com/webmasters/v3/sites/https%3A%2F%2Fwww.abcd.in?access_token={YOUR_ACCESS_TOKEN}

There is a bug in the explorer where it shows key instead of access token it has been reported to Google.

Once you have done that i recommend you find a client library in your chosen language to help you with the authentication part.

"message": "Login Required"

Means that you haven't authenticated your user properly. You should check the documentation for oauth2 or find a client library to help you code it.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • @DalmTo ... i have registered my project and and have also enabled webmasters api and created the got the client secret key and the client id . and as u said i have changed the url as : https://content.googleapis.com/webmasters/v3/sites/https%3A%2F%2Fwww.abcd.in/sitemaps?access_token=my_client_secret_key . But it is still saying "Login Required" code :401 – Aquarius Jan 02 '18 at 09:18
  • You need to authenticate your user. The client id and secret are used to request an access token. If you are doing that please update your question and add your authentication code. You might want to try reading this as well http://www.daimto.com/google-developer-console-oauth2/ – Linda Lawton - DaImTo Jan 02 '18 at 09:43