I am using Google plus auth to log in in web application. It is working properly, but for some time its return error 401. Error JSON is following. I view link Error Description but I did not understand what should I do.
{
"error":
{ "errors":
[
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
As the error page indicated - your access token has likely expired. It sounds like you got an access token once, and are continuing to use it.
Access tokens expire after an hour. After that time, you either need to go through the auth flow again, or use the refresh token to get a new one.
Related
I am using v4 and google/apiclient:2.9.1 (php).
I successfully access the spreadsheet through oauth2. It is meaning I can read and edit data. But sometimes I get 403 http code with a body
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"errors": [
{
"message": "The caller does not have permission",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
for no apparent reason. I don't change the permissions of spreadsheet, don't revoke permissions, etc. Re-access request is successful and the data becomes available again through API.
Why it happens? How do I get rid of the need to re-request access permissions?
This is repeated on different accounts and spreadsheets.
I am new to YouTube Analytics API.
Could you please help me to retrieve data from my associated YouTube channel.
I have populated the data using “youtubeAnalytics.reports.query” in the APIs Explorer window.
But when I am trying to use the below HTTP request
https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3D{MY_ASSOCIATED_CHANNEL_ID}&start-date=2016-08-01&end-date=2016-08-31&metrics=views&dimensions=video&filters=video%3D%3D{MY_VIDEO_ID}&max-results=10&sort=-views&key={MY_API_KEY}
It shows an error message “Login Required”
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
Could you please help me to correct my HTTP request to populate the data.
Thanks,
Aneesh
As far as I know most all of the YouTube Analytics API is private data. Being that its private data you need to be authenticated in order to access it.
Your error "Login Required" means exactly that you need to be authenticated to access the data you are requesting. Probably using the scope
https://www.googleapis.com/auth/yt-analytics.readonly
Once you have authenticated your application you can do access_token={Access token gotten from authentication} in order to access that data.
I run this request:
https://www.googleapis.com/drive/v3/files/1TcBDyugpHQSyUCLZcM0XtHOXo0S9Neh6asQUAYh54EM/export?mimeType=application%2Fpdf&key=[apiKey]
on this public file:
https://docs.google.com/document/d/1TcBDyugpHQSyUCLZcM0XtHOXo0S9Neh6asQUAYh54EM/edit
which is clearly exportable as PDF. I run this same query via Google's API explorer: Files: export
With whatever credentials it grabs, it tells me the response is 200 OK with application/pdf data. However, running the query manually in the browser gives me:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "internalError",
"message": "Internal Error"
}
],
"code": 500,
"message": "Internal Error"
}
}
I had a similar problem with a 400 using the normal File.get method:
https://www.googleapis.com/drive/v3/files/1TcBDyugpHQSyUCLZcM0XtHOXo0S9Neh6asQUAYh54EM?alt=media&key=[api key]
returning:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
Am I just doing something wrong? Any help appreciated!
API key is used for accessing PUBLIC data. Unless your file is set to public your not going get it using an API key. You will need to be authenticated using Oauth2 and use an access token
https://www.googleapis.com/drive/v3/files/1TcBDyugpHQSyUCLZcM0XtHOXo0S9Neh6asQUAYh54EM?alt=media&access_token=[token]
Error documentation:
400: Bad Request
User error. This can mean that a required field or parameter has not been provided, the value supplied is invalid, or the combination of provided fields is invalid.
Using OAuth code i am able to generate access token for google+ API .
using this access token in oauthpalyground iam getting JSON response .
When I paste this this URL into a browser am get an error message.
https://www.googleapis.com/plus/v1/activities?query=%22great%22&access_token=xxxxxxxxxxx
Error Message
{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}
],
"code": 403,
"message": "Insufficient Permission"
}
}
Can anyone explain to me why?
You can not query directly from browser sending the access_token as a querystring. You must send access_ token in headers this way:
Authorization: Bearer <access_token>
Try it with Fiddler or some similar software.
For some reason I’m not getting the results that I expected using the HTTP POST explorer. I’m getting 403 Forbidden for all userIds that I try.
I used this article to be sure I'm using the correct userId (I even used the userID from the article to see if it was just the ones I tested).
This is where I'm testing: https://developers.google.com/apis-explorer/#p/plusDomains/v1/plusDomains.activities.list
Could there be something wrong with the API?
Here's the full response:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
For the Plus Domain API, you need to make sure the user you're authenticating as is part of the domain you're making queries for. See https://developers.google.com/+/domains/authentication/ for more details.