How to fix Google Sites Feed API? - php

I have a project where the Google Sites API stopped working in March 2019. I am continuously getting the following error message.
I have checked necessary things like API is enabled, scopes and Google Admin API access enabled.
[26-Apr-2019 13:42:02 Europe/Minsk] PHP Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error refreshing the OAuth2 token, message: '{
"error": "unauthorized_client",
"error_description": "Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested."
}
google-api-php-client\src\Google\Auth\OAuth2.php(314): Google_Auth_OAuth2->refreshTokenRequest(Array)
google-api-php-client\src\Google\Auth\OAuth2.php(239): Google_Auth_OAuth2->refreshTokenWithAssertion()
google-api-php-client\src\Google\Service\Resource.php(214): Google_Auth_OAuth2->sign(Object(Google_Http_Request))
google-api-php-client\src\Google\Service\Directory.php(1703): Google_Service_Resource->call('list', Array, 'Google_S in google-api-php-client\src\Google\Auth\OAuth2.php on line 363
I have not made any changes to my code and to the CREDENTIALS in the Google Developer Console or to the G Suite. What could have gone wrong for the API to stop working suddenly?
Thank you very much in advance.

Got the same surprising behavior with a NodeJS script using Google Sites API.
In GSuite developer admin console, some scopes for Google Sites have been removed (!) a few months ago, and must be replaced by a new one:
Authenticate to https://console.developers.google.com
In the top bar, choose the project corresponding to your app
In the search field at the top, type "Marketplace SDK"
Choose option G Suite Marketplace SDK
Go to Configuration
In section OAuth 2.0 scopes remove scopes:
https://sites.google.com/feeds/site
https://sites.google.com/feeds/activity
https://sites.google.com/feeds/content
Add scope:
https://sites.google.com/feeds
click Save changes
This hint helped me. Using the OAuth 2 API playground shown a much more precise error when using an "old" scope (Invalid legacy scope provided)

Related

Method not found. error when using Google my business API

I am getting 404 from accouts list function by using google api client.
I have already access token by using OAuth2.0.
In addition to this, I already enable the Google My Business API via https://console.developers.google.com for OAuth 2.0.
â– Here is environemnt
PHP 7.2.3
Ubuntu 18.04 LTS
google/apiclient ^2.5
The function I want to execute is as following.
https://developers.google.com/my-business/reference/rest/v4/accounts/list
I install google client libray by using composer from following link.
https://github.com/googleapis/google-api-php-client
Since google my business library is seprated, I use this program.
https://developers.google.com/my-business/samples
The steps to produce 404 is...
$client = new \Google_Client();
$client->setApplicationName("post_dev"); // app name
$client->setApprovalPrompt('force');
$client->setAccessType('offline');
$client->setAccessToken($credential);
$client->addScope("https://www.googleapis.com/auth/business.manage");
$client->addScope("https://www.googleapis.com/auth/plus.business.manage");
$gmbService = new \Google_Service_MyBusiness($client);
$results = $gmbService->accounts->listAccounts();
The variable $credential has following values.
client_id
client_secret
access_token
expires_in
refresh_token
After executing program, I am getting 404 erros like follwoing.
Google_Service_Exception[
404
]: {
"error": {
"code": 404,
"message": "Method not found.",
"errors": [
{
"message": "Method not found.",
"domain": "global",
"reason": "notFound"
}
],
"status": "NOT_FOUND"
}
}
It happens because you are trying to interact with the Google My Business API using a non-whitelisted project.
I faced the same issue. In my case, I submitted my project for whitelisting to unlock Google My Business API library.
Then, a couple weeks after that I created a new project under the same Google Cloud Platform account, just to set a more appropriate name. HERE was the root of the issue!
Even if you see the GMB library enabled at the account level, it works only at the PROJECT level. That's why you are getting 404 errors.
So, I switched everything to my original project (Consent screen settings, Oauth clients, etc)... The same on my localhost application, developed with Laravel Lumen 7.
After these couple changes, everything worked fine!
NOTE: Google allows you to whitelist 1 project per account ONLY! If your project/application were approved by Google, USE IT! Instead creating new ones.
This error has nothing to do with your access token. It cant find the method you are using. Google_Service_MyBusiness is not part of the Google api php client library.
The my Business API is unlike the other apis, it is not listed in the API directory available through the Discovery API and it requires a developer key and project acceptance into My Business. There for it cant be generated when the library generation script runs.
Im going though some channels to get that documentation page updated.
note from team Nov 1, 2018
There is a tool on the way that will help developers maintain their own version of such service classes. When it is ready and you have a project with My Business enabled you should be able to run:
export API_KEY=yourkey
bin/generate 'https://mybusiness.googleapis.com/$discovery/rest?version=v4&key=$API_KEY' generated-output
and then you can move the contents of generated-output/mybusiness-v4 anywhere you want in your include path.
That discovery URL has been known to change as new versions come out so keep and eye on https://developers.google.com/my-business/reference/rest/
Im waiting to hear the status of this.
The reason why I could not call the API is "my company already has a whitelisted project to access the Google My Business API. At this time, they are only whitelisting one project per business.". Therefore, I could not call API.
So far I'm able to use the PHP Library here - https://developers.google.com/my-business/samples/previousVersions
But the answer above was a huge help - I had EXACTLY the same issue, had "tidied up" my projects - after being granted access to the Google My Business API and seeing it available for my other projects I assumed incorrectly that my other projects would be able to use it - wrong! Very glad I found the answer here. Luckily I was able to restore the project I'd deleted, and using that one it worked straight away.

Need to pay 25 USD to use Google Oauth2 authentication?

I used my google account developer for quite a long time (2-3 months).
I created a Google Oauth2 app, got clientid, access token and all the stuff. Working perfecty. My website's using a PHP client for OAuth2 auth.
Today I'm went to the website and I received the error:
Error fetching OAuth2 access token, message: 'invalid_request: Missing
parameter: client_id'
I went to my developer console (thinking the client_id was different for some weird reason) and I found out I can't access the console anymore, Google is asking me a fee of 25 USD to access again.
Is it normal? Why such a misleading error message from the PHP client?

Google Adwords API "An error has occurred: { "error" : "invalid_grant" }"

I've been crawling the internet all morning trying to figure this out. I'm trying to get access to a Adwords test account through the API but I keep receiving "An error has occurred: { "error" : "invalid_grant" }". I've seen this is quite a common problem so perhaps if I outline what I've done step by step someone can correct me. Hopefully!
Created a Google adwords account and set up a campaign.
Created a MCC account. Added Google adwords account and applied for API access (pending). Noted API key, client id for auth.ini.
Created a test MCC account and added Google adwords account. Noted client id for auth.ini.
Using the Google account of both MCC accounts went into the API console and created a new installed application app. Noted all keys/tokens.
Downloaded the PHP code examples and libs. Ran get GetRefreshToken.php, granted accesses to app(s) and noted refresh token for auth.ini
Set up auth.ini populating developerToken, userAgent, clientCustomerId, client_id, client_secret and refresh_token.
Now I've tried using BOTH sets of tokens and ids from the test MCC account API console and the live MCC account API console. Both give me the same error. I've tried regenerating all tokens several times.
Gave up and came crawling to StackOverFlow.
Is the invalid_grant message related to Auth or my developerToken token not being activated yet (sure it said I could use my test account though) or because I haven't set up any of the billing?
In my case the problem was at step 5 in your list; I had copied the authorization code from my browser after granting access, rather than the refresh token generated by GetRefreshToken.php after I pasted the authorization code there.
I had the same situation for a long time.
But solution was very simple.
The code getting after authorizing the Google is not your refresh token.Its is only an access token(I guess.)
You have to add this code to GetAccessToken's $code variable function in getrefreshtoken.php file and it will return the actual Refresh token.
This solved my issue.
It is very important to note that the SDK is designed to be used through PHP-Cli. So please don't use it via browser. If you still run it by commenting out return line you'll get into further problems to comment that on each file :)

Google Authentication Using PHP Library OAuth 2.0

After many many hours searching I am still unable to figure out why I am receiving this error. It worked for a month and without touching any code, stopped working last night. The web app has been registered and Google+ api is turned on.
Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling GET https://www.googleapis.com/oauth2/v2/userinfo?key=MYKEY: (403) Access Not Configured. Please use Google Developers Console to activate the API for your project.'
I enabled Google+ Domain API just to see if it did anything. It allowed me to login 1 time and then continued to fail after that.
The developer key should be OK to pass every time as long as it matches the project that has been used for sign in (e.g. the client ID and the key come from the same developers.google.com/console project).
There was a problem yesterday with the userinfo endpoint that caused 403 for a number of users - that has now been resolved, but my guess is you were hitting that unfortunately!
So after further research and testing, I think I have the solution.
As mentioned by Jason OOO, $client->setDeveloperKey($key); was causing the problem.
As it turns out, Google PHP library needs $client->setDeveloperKey($key); passed the first time for validation, but causes an error if passed again after already being validated.
So, to fix this problem, check to see if user is already logged in and if they are do not pass $client->setDeveloperKey($key);

Google Glass Development Error: (403) Access Not Configured. Please use Google Developers Console to activate the API for your project

I am using the PHP version of the Google Glass Developer Kit. Setup everything per the sample code instructions. API/credentials are all fine, account billing is setup, have added the Mirror API to the project, but after I permission the application, I get the following Error:
An error ocurred: Error calling POST
https://www.googleapis.com/mirror/v1/timeline?key=xxxxxx
(403) Access Not Configured.
Please use Google Developers Console to activate the API for your project.
I have added the Mirror API and have Billing active and setup so have no idea why i am getting the error message. Testing the app via the Glass Explorer works just fine.
Google APIs have been known to misbehave when you provide both OAuth2 credentials and an API Key. Also since you have to use OAuth2 to access the Mirror API, the key=xxxxx isn't necessary anyway.
If you are using the Google APIs Client Library for PHP you can simply remove the following line from your code:
$client->setDeveloperKey($key);
Not entirely sure if this causes your issue, but I have come across similar issues in other Google APIs.
In Google API console for your project (https://code.google.com/apis/console/)
Make sure that your "Public API access" or "Key for server application" has allowed the IP address of your server.
Also make sure you have the proper "Redirect URIs", if you get refused, look at your php logs, I had this:
PHP Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling GET https://www.googleapis.com/mirror/v1/timeline?maxResults=3&key=: (403) Access Not Configured. Please use Google Developers Console to activate the API for your project.'
use your $base_url + /oauth2callback.php to find out what the correct Redirect URI is.
I managed to solve the issue by adding the IP address and REDIRECT URIs and it runs both on my local machine and on the server. (same code, same key)
PS: I want to thank Scarygami, disabling the $client->setDeveloperKey($key); helped me find the solution.

Categories