I am working on the GMB API, facing some issues. I have implemented Google Oauth at frond-end and saving user listing in my DB. Now I want to run cron job in which I want to get those user`s listing insights. So issues are here
1: I can't find GMB API samples or doc regarding GMB stuff(I have read all google-api-php-client doc).
Here are GMB samples but it doest have PHP samples.
https://github.com/google/google-my-business-samples
2: Second thing is that I don't want to open consent(Google Account Selector Popup) to get the user's permission because its a backend process. So what type of process should I follow a) Oauth OR b)Service Account.
If I use the Oauth process then I have to save access_token in the database when the user first time gives permission at the front end of the website and uses that token as refresh token to get the new access token in PHP and call GMB APIs.
But the issue is that we have already registered 500+ users, so how I will get their access token because they are already done with google permissions.
I didn`t try yet with a service account.
I am using Laravel 5.7 version.
Related
I am using the Google API Playground to auth my PWA and get tokens to upload files to google drive from the PWA.
I'm using the Google Drive API, but the refresh token that I got from the Playground is expiring after one week. This causes us to go through the whole process from playground again.
I don't have this problem with other APIs, such as Dropbox, where the app refresh tokens aren't expiring and can be used to generate a new access token.
I am looking for help in:
Authorizing my PWA and get code in php using curl
Get a refresh token through my PWA without a consent screen
Lets take this step by step
I'm using the Google Drive API, but the refresh token that I got from the Playground is expiring after one week.
I am going to assume that you are using your own client id and client secret within Playground.
If this is the case then the reason it is expiring after a week is that your app is still in the testing phase. To fix that you can go to google cloud console under the oauth2 consent screen and switch your app to prodctuion.
Request a new refresh token and it should not expire.
If you are not using your own client id then the reason its expiring is that developer console is not intended for production use its just for testing. Stop using it in that manner.
Get a refresh token through my PWA without a consent screen
If you only connecting to a single google drive account then you should consider using a service account. A service account is intended for server to server authorization its pre authorized. You can share a folder with a service account and the service account will have access to that folder without requesting a user grant consent. It will just work.
Current Working Flow
I have a web app (developed in wordpress)
I am using google-drive-sdk to upload dynamically generated pdf file to a GMail account.
The GMail account has been configured in the web app giving the
secret key ....
The web app first makes the authentication ===>i.e The GDrive Account is authenticated for the first time by the GMail owner (In Google Permission window the button Allow Access is clicked)
It works fine thereafter when called from the web app - the pdf file dynamically generated gets into the configured GDrive
The Problem
PDF files gets uploaded to the GDrive only for some time.
After sometime it doesn't upload the files to GDrive.
I then tried creating a new token - It again starts uploading files but stops after some time.
This happens only in Staging server.
In my local development system it keeps working fine - uploading the file to GDrive whenever the app is executed.
The difference between both the environment is the GMail Account is different.
If you have any idea on the cause of issue or any pointers would really be helpful for me.
Your application must use OAuth 2.0 to authorize requests. All requests to the Drive API must be authorized by an authenticated user.
The details of the authorization process, or "flow," for OAuth 2.0 vary somewhat depending on what kind of application you're writing. The following general process applies to all application types:
When you create your application, you register it using the Google API Console. Google then provides information you'll need later, such as a client ID and a client secret.
Activate the Drive API in the Google API Console. (If the API isn't listed in the API Console, then skip this step.)
When your application needs access to user data, it asks Google for a particular scope of access.
Google displays a consent screen to the user, asking them to authorize your application to request some of their data.
If the user approves, then Google gives your application a short-lived access token.
Your application requests user data, attaching the access token to the request.
If Google determines that your request and the token are valid, it returns the requested data.
Some flows include additional steps, such as using refresh tokens to acquire new access tokens. For detailed information about flows for various types of applications, see Google's OAuth 2.0 documentation.
I am trying to connect to the Facebook Graph API using the PHP SDK and view recent posts of a business account. BTW: I know there is a widget available for this task, but due to speed constraints, I would rather access the API and cache the response myself.
So I used my personal account to sign up at developers.facebook.com, created an app and obtained an AppId and AppSecret. My question relates to obtaining an access token for use with the graph API using the PHP SDK.
The examples on the getting started page shows how to obtain an access token by manually clicking a link and receiving a callback to my website. I am not creating a public app as such, I don’t want a manual login because my script will be run periodically by the server.
In any case if I click the Log in with Facebook! link, I get the following message which I don't understand:
The Twitter API provides automatic authentication but I cannot understand how to impliment this using Facebook. Can anyone point me in the right direction?
Previously I had a working php script that uses the Zend_Gdata_ClientLogin Object to authenticate and make requests on my behalf to delete videos from my YouTube channel. Apparently, this has been deprecated because I get an error and read this: zend gdata and google spreadsheet not connecting
And I get an error which says no longer available. So I've been researching how to use YouTube API v3. Initially I created a service account via the Google developer console.
However I found this
YouTube API v3 with OAuth2: update and delete fail with "Insufficient Permission" error
Which states:
For the uninitiated, the YouTube Data API (v3) does not support
"service accounts,"
And I need to manually obtain a refresh token, to make requests?
Is this still the case? Surely, there must be an easier way to make authenticated requests to the YouTube API where the only client is my server?
If this is still true, how long will the refresh token work? Is this the best practice?
You can check out the documentation to see the most up to date way to request the access token. When the access token expires, your application can refresh it by sending a POST request to Google's authorization server using the refresh token. You only need to get this refresh token once in order to refresh your access token, not every time you want to make authenticated requests, if that's what you were thinking.
The refresh token should be valid unless:
The user has revoked access.
The token has not been used for six months.
The user account has exceeded a certain number of token requests.
There is currently a 25-token limit per Google user account, so if your application requests too many refresh tokens, it may run into this limit and older refresh tokens will stop working.
I can't speak as to whether this is the best way of doing it, but I assume the developers chose this way for a reason.
I'm currently using the GAPI tool to extract date from my Google Analytics account using an OAuth 2.0 account created in the Google Developers Console. It works flawlessly except for one thing - every so often, the script will fail with the following message:
'GAPI: Failed to request report data. Error: "{"error":{"errors":[{"domain":"global","reason":"authError","message":"Invalid Credentials","locationType":"header","location":"Authorization"}],"code":401,"message":"Invalid Credentials"}}"
My assumption is that the Oauth 2.0 token is expiring, preventing further data access. I have been manually restarting the process so far, but it would be far more efficient to automatically refresh the token prior to expiration. If anyone knows the best way to accomplish this, I'd appreciate hearing it. Thanks.