Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential

I am trying to update Google sheet values.

"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential."

I want to do this using API key not outh 2.0

Can anyone have any suggestions.

like image 732
Rana Ghosh Avatar asked Oct 03 '17 13:10

Rana Ghosh


2 Answers

Not possible. You need to use the OAuth login as indicated here in spreadsheets.values.batchUpdate:

You can see on the authorization part that it uses OAuth scopes, therefore it follows that it uses OAuth not API KEY:

Authorization

Requires one of the following OAuth scopes:

https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/spreadsheets 
like image 104
noogui Avatar answered Sep 20 '22 19:09

noogui


I am facing similar type of issue.

Issue Analysis: Actual issue is missing of scope.

Solution: Scope can be added by the following ways:

  1. using enabling api
  2. Adding oauth scope list. List is available here: https://developers.google.com/identity/protocols/googlescopes
  3. Adding scope from Code level

Details are available here:

  1. If any scope is missing, first we need to check that related api is enabled or not. If not enabled yet, go first on google console and enable api.

Procedure is available here: https://support.google.com/googleapi/answer/6158841?hl=en

  1. After enabling api, sometimes you will not get your expected scope. If there is any sophisticated scope is required, you need to add those in your scope list. For this, you need to follow the procedure:

    i) Go to google console

    ii) Select your project

    iii) In left sidebar, you will get "Oauth consent screen". Click on that button

    iv) You will get "Add scope" button. There is actually 3 is enlisted primarily: email, profile and openID

    v) You can add your expected scope here.

  2. In code level, we can also add SCOPES. In code level, I am using singleton list. Which is always using single scope. So when I need another scopes like user profile or user email. I can't reach those. So I changed it and got my expected result.

Previous Code:

private static final List<String> SCOPES = Collections.singletonList(DriveScopes.DRIVE); 

After change:

private static final List<String> SCOPES = new ArrayList<>(             Arrays.asList(DriveScopes.DRIVE,                     Oauth2Scopes.USERINFO_EMAIL,                     Oauth2Scopes.USERINFO_PROFILE,                     Oauth2Scopes.PLUS_ME)); 
like image 36
SkyWalker Avatar answered Sep 21 '22 19:09

SkyWalker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!