Currently I am trying to get reviews from https://play.google.com/store/apps/details?id=com.rosterelf.android.phone&hl=en by following https://developers.google.com/android-publisher/api-ref/rest/v3/reviews/list documentation.
I am using the PHP (cURL) method but I am keep getting an error saying --- Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.
Below are my steps what I have done / tried so far.
Created one Api KEY, OAuth 2.0 Client ID and Service Account in Google Developer Console.
Enabled the Google Play Android Developer API and Google Play Custom App Publishing API too.
Going at my browser https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&redirect_uri=REDIRECT-URI&client_id=CLIENT-ID
It gives me the code in response and then to be able to get access_token, I am using below PHP cURL code which is also working fine.
<?php
$client_id = 'CLIENT-ID';
$redirect_uri = 'REDIRECT-URL';
$client_secret = 'CLIENT-SECRET';
$code = 'CODE';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://accounts.google.com/o/oauth2/token");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'code' => $code,
'client_id' => $client_id,
'client_secret' => $client_secret,
'redirect_uri' => $redirect_uri,
'grant_type' => 'authorization_code'
));
$data = curl_exec($ch);
var_dump($data);
exit;
And in response, I am successfully able to get the access_token.
Now I am trying to go directly to this page in browser https://www.googleapis.com/androidpublisher/v3/applications/com.rosterelf.android.phone/reviews?access_token=ACCESS-TOKEN but it keeps saying me...
Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project
-> I have checked the roles and permissions and it has owner as a permission in service account.
-> My REDIRECT-URI also the same URL throughout this process.
I event tried this URL to fetch the reviews https://androidpublisher.googleapis.com/androidpublisher/v3/applications/com.rosterelf.android.phone/reviews/review?access_token=ACCESS-TOKEN but having the same error.
Can someone please guide me what am I missing from here and why I am getting here and what exactly I should do from here on to get the reviews ?
Any help or suggestions will be highly appreciated.
Thanks in advance.
This is an example for that API using the official client library. I believe this code is for service account authentication. The service account will need to be properly configured see using_a_service_account How to create service account credetinals just remember to enable the proper library.
<?php
require_once 'google-api-php-client-2.2.2\vendor\autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=client_secret.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_AndroidPublisher::ANDROIDPUBLISHER);
$android_publisher = new Google_Service_AndroidPublisher($client);
$response = $android_publisher->reviews->listReviews('appname');
echo "<pre>";
var_dump($response);
Related
I am learning to build a Login via Google button on my Joomla website, and I am following instruction on https://developers.google.com/identity/protocols/oauth2/web-server.
A little background:
I am using a third party extension to handle social login. Its facebook login works well, but its google login is outdated, still trying to connect to Google Plus endpoints. Clicking the login button on my page does lead to Google's account choice screen, after I choose an account and grant permission, there is a simple error message on the callback page. The author has stopped updating the extension, so for learning purpose, I've decided to fix it myself.
What I've achieved:
Currently I was able to get the access token from Google.
.......
$postdata = array(
'grant_type' =>'authorization_code',
'client_id' => $this->params->get('goappid'),
'client_secret' => $this->params->get('gosecret'),
'redirect_uri' => $this->getRedirectURL().'&task=gologin',
'code' => $_GET['code']);
curl_setopt($curl, CURLOPT_URL, 'https://oauth2.googleapis.com/token');
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postdata));
$oauth = json_decode(curl_exec($curl));
// Above code seems to be fine, getting $oauth response as follows
// "access_token": "token string",
// "expires_in": 3599,
// "scope": "https://www.googleapis.com/auth/userinfo.profile",
// "token_type": "Bearer",
// "id_token":"token string"
if (isset($oauth->access_token)) {
curl_setopt($curl, CURLOPT_POST, false);
curl_setopt($curl, CURLOPT_URL, 'https://www.googleapis.com/plus/v1/people/me?access_token='.$oauth->access_token); //Apparently outdated endpoint
$user = json_decode(curl_exec($curl));
if (empty($user->error)) {
curl_setopt($curl, CURLOPT_URL, 'https://www.googleapis.com/plus/v1/people/me/activities/public?access_token='.$oauth->access_token);//Apparently outdated endpoint
My question: At this point, I don't know what to do. The instruction says After your application obtains an access token, you can use the token to make calls to a Google API on behalf of a given user account, but how do I "make calls to a Google API"? To make a simple login via Google button, which API should I call? And to what endpoint should I make the request? I can't find this information from the instruction page. Above code is making request to https://www.googleapis.com/plus/v1/people/me?access_token, which is obviously outdated but how should I change this? This should have been provided by the instruction but I couldn't find it. And if I want to access other Google APIs, how do I "make calls" to them? a.k.a where do I find endpoints for each API?
I've also read https://developers.google.com/identity/protocols/oauth2/openid-connect, is what I am trying to do considered OIDC? Should I proceed according to this document?
I still think that access_token in the query path works in some Google apis. until June 2021
GET https://www.googleapis.com/plus/v1/people/me?access_token=[token]
I recommend switching to using an authorization header
GET https://people.googleapis.com/v1/%5BRESOURCENAME%5D HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
I'm trying to create an application on LinkedIn that's using OAuth2 for authentication and am running into some errors. The client runs on an iOS device and uses an oAuth library to make a call to LinkedIn's servers. My iOS client successfully gets the authorization_code. The client application then passes that authorization_code to my server, which attempts to connect to linkedIN again and get the access_token. This step consistently fails, I get the following error from LinkedIn: {"error":"invalid_request","error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : client_id"}
My POST method to LInkedIN does contain the client_id, it only contains it once, and I've triple checked the values for all the parameters, they are correct. I've also reset the access multiple times from https://www.linkedin.com/secure/settings and I've even created additional applications on LinkedIn, I keep getting the same result.
I've checked other responses, such as this one: unable to retrieve access token linkedin api and tried the suggestions: revoke keys, request new keys etc, nothing seems to be working.
Here is my server code:
$tokenURL = 'https://www.linkedin.com/uas/oauth2/accessToken';
$redirectURL = 'https://staging.textsuggestions.com';
$clientId = '75a4ezqh741sup';
$clientSecret = 'XXXXXXXX';
$tokenArguments = array("grant_type" => "authorization_code",
"code" => $code,
"redirect_uri" => $redirectURL,
"client_secret" => $clientSecret,
"client_id" => $clientId);
// send the request to the server getting data
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $tokenURL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $tokenArguments);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
if (!empty($response["error"])) {
error_log("Error is: " . $response["error"]);
exit (0);
} else {
// no error, get the access_token and do stuff with it
$timeout = $response["expires_in"];
$access_token = $response["access_token"];
}
Ok I realized what I was doing wrong, the client application library that I was using was generating the full access token (not the auth code). So I was trying to pass in the access token in the place of the auth code. The error that I was getting from Linked In was certainly misleading and I should have checked the client library I was using more carefully.
Have you tried to check your code against this code sample?
https://developer.linkedin.com/documents/code-samples
Check that the POST headers include "Content-Type": "application/x-www-form-urlencoded".
My goal is to make a LinkedIn company updates feed on a website using the Linkedin PHP REST API or JavaScript api. This feed needs to be available to any user visiting my website, however, all the codes samples I can find are asking me to redirect visiting users to Linkedin for OAuth so I can get an access token to make API calls. This is not what I need.
How can I make API calls for my company for any anonymous user coming to my site (without any redirection to LinkedIn)? This must be possible. I have registered an application already on Linkedin and received:
API Key: XXXXX
Secret Key: XXXXX
OAuth User Token: XXXXX
OAuth User Secret: XXXXX
A related question is what are the OAuth User Token and OAuth User secret for that were supplied to me when I registered my Linkedin application?
If you already have a token then check the part in the documentation about fetching the profile, it works exactly the same for company updates, just different url: https://developer.linkedin.com/documents/code-samples
Here's the PHP code required to obtain company updates:
$token = "<your_access_token>";
$url = "https://api.linkedin.com/v1/companies/<company_id>/updates";
$headers = array(
'Authorization: Bearer ' . $token,
'x-li-format: json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
Use the code in the link from the other answer to obtain an access token for your client.
I know there are a lot of similar questions here in SO but I tried these solutions for hours but they didn´t work for me. I always get a { "error" : "unauthorized_client" }". I want to programmatically refresh my accesstoken to use the Youtube API. I already have gained a refreshtoken.
This is what I´ve come up with:
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'client_secret' => '<mysecret>',
'grant_type' => 'refresh_token',
'refresh_token' => '<my_refresh_token>',
'client_id' => '<my_client_id>.apps.googleusercontent.com',
'redirect_url'=>'<my_redirect_uri>'
));
curl_setopt($ch, CURLOPT_URL, 'https://accounts.google.com/o/oauth2/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
echo var_dump(curl_exec($ch));
Whats wrong with it?
The URL and query params you've indicated look right to me. Seems like this error would come up if the client_id you provide to generate new tokens is different than the client_id provided to obtain the refresh_token.
One thing that might be happening is that if you have generated an access_token and refresh_token using Google's OAuth playground, and then trying to use that refresh_token to generate new tokens -- this will not work. The Google OAuth playground is using different client_ids to make that request, and this will definitely result in the "unauthorized_client" error you've documented.
Temboo has a very concise and easy-to-use OAuth library for Google. You can check it out here: https://www.temboo.com/library/Library/Google/OAuth/.
(Full disclosure: I work at Temboo)
What I have:
Twitter app created at twitter and PHP app at localhost
What I want:
post tweets/update statuses via twitter API from only(!) the app account.
No twitter#anywhere, no user login, nothing fancy.
What I tried:
https://github.com/abraham/twitteroauth with access tokens from the dev.twitter.com website, returned
"POST data is not available with this
token"
or something like that.
code snippet I found on some website:
// Define credentials for the Twitter account
define('TWITTER_CREDENTIALS', 'username:password');
// Set up CURL with the Twitter URL and some options
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://twitter.com/statuses/update.xml?status=test_status');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Twitter uses HTTP authentication, so tell CURL to send our Twitter account details
curl_setopt($ch, CURLOPT_USERPWD, TWITTER_CREDENTIALS);
// Execute the curl process and then close
$data = curl_exec($ch);
curl_close($ch);
// If nothing went wrong, we should now have some XML data
echo '<pre>'.htmlentities(print_r($data, true)).'</pre>';
returned
"Basic authentication is not
supported"
That big code snippet uses basic authentication, which is no longer supported by Twitter. Disregard it.
OAuth is now required by Twitter instead, which is what abraham's twitteroauth library uses. You will have to log in/authenticate using this, at least once.
You will also have to first register your app with Twitter, to receive your own Consumer Key and Consumer Secret. Then you'll be able to start using Twitter's API via twitteroauth.
Okay I've found what's the problem.
By default, Twitter sets all apps to read-only, so even when you login via PHP, you can't send POST/UPDATE. What you need to do is go to your application settings (the one where you set app name, description and avatar) and before avatar there's a "default access type", switch it to
Read, Write, & Direct Messages
and voila.
to test the app use this snippet
$twitter = new \TwitterOAuth('consumer_key', 'consumer_secret',
'(oauth_token', 'oauth_token_secret');
$twitter->get('account/verify_credentials');
$twitter->post('statuses/update', array('status' => 'test status'));
Oh and you don't need to do the login stuff with your app, you get the required tokens under "My access Token" menu.