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.
Related
I am new to GoogleAPIs and Laravel, I run a PHP web application on Laravel 8 in a virtual Linux environment. Socialite and Drive API was working fine and out of sudden it doesn't work anymore and always return connection refused error after long period of loading as follows:
GuzzleHttp\Exception\ConnectException
Connection refused for URI https://www.googleapis.com/oauth2/v4/token
I had tried to create a new credential with new refresh token and checked all the network settings, and always clear config cache and restart apache for all troubleshoots I have tested, yet the error still exists.
I would appreciate it much if anyone could enlighten me on what are the aspects I shall look into it.
There are multiple issues in this question.
First and foremost, you are sending your secret to a third party. This means that they are able to do any API calls as you (using your name and quotas). Even if they claim that they won't, they can. Please remove any secret you may have and create new ones.
As for the OAuth 2.0, you seem to be using an old URL. You should probably take a look into the official documentation for:
Using OAuth 2.0 to Access Google APIs for a basic explanation.
Using OAuth 2.0 for Web Server Applications for making a web and getting permissions to get/modify a user's data (can be yourself).
Using OAuth 2.0 for Server to Server Applications for using a service account to execute as one of the users on your organization, without the need of manually giving permission.
Also notice that there are PHP libraries officially supported by Google to make your life way easier. See the Drive API's PHP Quickstart.
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)
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.
I have a basic Android app setup which registers itself to recieve push notifications through google.
I get the key and I store it which I can then use to manually add the device as an endpoint in the AWS control panel.
Now I would like to do the manual step in the background so I lookup the documentation and come to this: http://docs.aws.amazon.com/AWSSDKforPHP/latest/#m=AmazonSNS/subscribe
It looks like this requires the user to verify they want to be on the list but this is something to worry about later.
However, I can't make it work.
If I choose https as the protocol I get "Invalid parameter: Endpoint must match the specified protocol" which I am guessing means that the string I get back from Google isn't what it wants. I don't understand this because it works if I put it in manually. I have tried the sqs protocol but I suspect that I am trying the wrong method entirely - I just can't see another method that the API supplies that would do what I need.
I find the AWS documentation a bit rubbish (although I am aware it's an outdated API) and the their forums are nowhere near as proactive as the people on here. :)
I answered this question on the AWS PHP Development forum:
SNS push notifications is a newer feature and is not a part of version 1 of the SDK. You should consider upgrading or seeing if it's feasible to use version 2 of the SDK side-by-side with version 1.
I have an idea that you could try, but I haven't tested it myself, so I'm not sure if it will work. Try setting the $protocol parameter to "application" as described in the version 2 API docs for subscribe(). Then set the $endpoint parameter to the "EndpointArn of a mobile app and device". Since the API version of the Amazon SNS service hasn't changed from version 1 of the SDK to version 2, there is a good chance that this might work.
I developed a app to read over someones inbox for keywords. If found to give them a score. It worked fine for awhile however now it does not. WHen I try to manually put in the information into the graph api (https://graph.facebook.com/(id)//threads?access_token=(token)) I get this error:
{
"error": {
"type": "OAuthException",
"message": "(#298) You must be a developer of the application"
}
}
Any ideas on how to fix this issue?
It sounds like your application got disabled, potentially for violating the terms of service. I would contact the Facebook developer team on their Facebook group. I just tested this API call with my own application and it worked just fine with read_mailbox permissions. Try creating a separate application and trying again.