RGA Invalid Credentials - r

I try to use the RGA Package (https://github.com/artemklevtsov/RGA) to get Data from Google Analytics core API.
authorize(
client.id=options()$apiSecrets$id,
client.secret=options()$apiSecrets$clientSecret,
cache=paste(getwd(),"daToken",sep="/")
)
So the cache is set to something like /User/foo/bar/daToken. I can see the file and everything works just right, I can access the data for now. After 30-60 minutes however the token expires it seems. Now on a new attempt there will be the error message Error : client error: (401) Unauthorized Auth error: Invalid Credentials
Why is the token not working any more? How to setup a longer live time? Plus: why is there an error and why does RGA don't try to get a new token?

Please read Google Oauth 2.0 documentation properly.
Access Token has lifetime of only 3600 seconds. After that you have to use Refresh Token to get new Access Token.
I have not used RGA package but I am sure there must be some mechanism to validate and refresh the Access Token.

Related

`redirect_uri_mismatch` error when using Google as the signin provider

I have seen many posts for this error and all of them said to add my URL under both the API key that's generated by Firebase and the OAuth 2.0 Client IDs.
My domain is lyricsandquotes.org so I added the URL in both of these.
The screenshot from the API Key:
The screenshot from the OAuth:
However, I am still getting this error. What am I doing wrong?
I noticed I had to change the redirect URI under the Client ID credentials to the one specified in the error message:

Failed to refresh Access Token when using Google OAuth2.0 credentials

I am trying to use GA4 API (with Google Python Client & Google Analytics Data Python Client) of Google with the Credentials authentication:
credentials = Credentials(
token=config['access_token'],
refresh_token=config['refresh_token'],
client_id=config['client_id'],
client_secret=config['client_secret'],
token_uri="https://accounts.google.com/o/oauth2/token",
scopes=['https://www.googleapis.com/auth/analytics.readonly']
)
This is working when my access token is not expired. However, this access token is expiring after 1 hour and I want to refresh it via following method:
credentials.refresh(google.auth.transport.requests.Request())
However, this code is returning "invalid_grant" error.
For that problem, I checked almost everything suggested (i.e. system clock/ntp, user permissions, etc.) however I couldn't fix the problem.
Also, I can't figure out about the refresh_token that I use is valid for Google Analytics 4 or not.
So, the questions are:
How can I able to solve this problem?
How can I assure that the refresh_token is valid for GA4?
If not valid, how can I refresh the refresh_token?
Is there any suggestion on the refresh of access_token, any other method or anything else?
Thanks
In my case, the solution was creating new OAuth client and generate a refresh_token for that account depend on the Google Analytics scope.
For that purpose, after I create the new client, I downloaded the client_secrets.json and run the Complete Example by Google and finally I am able to refresh the token.

How To Refresh Microsoft Graph Access Token

I'm using firebase and I'm trying to create a backend function that can fetch an access token using a refresh token.
I've been following along with the Microsoft Graph Documentation for refreshing an access token but I can not get it to work.
I don't understand what I could be doing wrong or even how to go about debugging this. Could it have anything to do with the redirect uri that is set in azure console?
As,i can see you are got "invalid_grant" error , please try a new request to the /authorize endpoint and verify that the code_verifier parameter was correct.
Please
Reference doc- https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#error-codes-for-token-endpoint-errors

facebook offline_access error

to access users info when they are offline,
the user grants offline_access and I store them by this :
$session=$facebook->getSession();
if($session)
{
$access_token=$session['access_token'];
}
$qq=sprintf("insert into `tokens`(`uid`,`access_token`) values ('%s','%s')",$myid,$access_token);
$res1=mysql_query($qq);
but when I try to use graph.facebook.com to collect information from them , it sometimes work and some times doesn't and gives me this error :
Error validating access token: Session does not match current stored session. This may be because the user changed the password since the time the session was created or Facebook has changed the session for security reasons
i use graph.facebook.com/[function]?access_token=[the access token saved in DB]
what's my fault?
First, the access token with the offline_access permission can become invalid if :
the user de-authorizes your app in his privacy settings
the user changes his password
You can read a blog post from Facebook about how to handle expired tokens.
Then, you should not :
make API urls directly with URLs, like you do when you call graph.facebook.com/[function]..., but use the Facebook PHP SDK functions to make API calls.
use the version of the PHP SDK you are using ($facebook->getSession() is from v2.x) is deprecated, that might be the causes of your problems.
Here is an answer on Stackoverflow about how to handle offline_access access tokens with the Facebook PHP SDK v3.x.
Hope that helps !

Hybridauth LinkedIn API - Invalid Token issue

I have configured HybirdAuth for social logins as my all other social logins are working but suddenly linkedIn stop working and shows this error.
Original error message: Authentication failed! LinkedIn returned an invalid Token.
I have search and try different methods but nothing worked out.
I have change keys, create new apps, make some changes in the code.
Please help.
Seems like you are using invalid consumer key.
[`message] => [unauthorized]. The token used in the OAuth request is not valid. consumerKey: 77zl215zorlwwd`
Double check your app settings for consumer key.

Resources