oauth_problem=consumer_key_rejected using Scribe library - java

I registed for a Yahoo Messenger SDK api and plugged-in the consumer key/sercret into this code:
https://github.com/fernandezpablo85/scribe-java/blob/master/src/test/java/org/scribe/examples/YahooExample.java
However, I'm getting this error:
Exception in thread "main" org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this: 'oauth_problem=consumer_key_rejected'
at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:41)
at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:27)
at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:52)
at com.yahoodemo.YahooExample.main(YahooExample.java:28)
I'm pretty sure that the consumer key/secret is correct because I can get the 'RequestToken' using the same key/secret with a generic HTTP GET request.
Is this a bug in the Scribe library or it's something else?

Even i faced the same problem. But i finally found that:
In developer accounts (http://developer.apps.yahoo.com/projects) After creating the project, Don`t forgot to give alteast one permission for the application like: Contacts - READ, Knowledge Plus- READ. Finally save

The solution from Nagendra worked for me but don't forget to refresh the Yahoo Project page as both the key and the secret code are changed after editing the permissions.

Related

Getting Error when try to get Pinterest Access Token

My question is similar to this one.
I have followed every step trying to get a Pinterest access token.
https://developers.pinterest.com/docs/api/overview/
I '
1. Created an app in the Pinterest developer dashboard
2. Got my authorization code without any problems
3. Tried to query my access token like in the docs:
POST https://api.pinterest.com/v1/oauth/token?grant_type=authorization_code&client_id=888888888888888&client_secret=9999999999999999999999&code=00000000000000
I tried to get it using curl command also.
Using Postman to get an access token is possible(Configure the OAuth flow:).
But from java or postman i pull above endpoint then getting this error {"error": "invalid_grant"}
Can anybody help me and tell me what could go wrong and how to fix it?
Thank you!

Why is GetServerAuthCodeResult Deprecated? How can I do something equivalent in an Installed Application?

Following this post: http://android-developers.blogspot.com/2016/01/play-games-permissions-are-changing-in.html I have obtained a single use authorization code for use on my backend server as follows:
import com.google.android.gms.games.Games;
//later
Games.GetServerAuthCodeResult result = Games.getGamesServerAuthCode(gameHelper.getApiClient(), server_client_id).await();
if (result.getStatus().isSuccess()) {
String authCode = result.getCode();
// Send code to server...
This seems to works fine, but it presents a question:
1) getGamesServerAuthCode and GetServerAuthCodeResult are marked as deprecated. Why? Should I be using something else instead?
2) How would I do something equivalent in an non-Android installed Java application? I am able to obtain a token on the client application, but I also need to obtain a single use code to pass to my backend server like above. I can't find an equivalent function to get a Server Auth Code. (using com.google.api.client.extensions.java6.auth.oauth2)
I am basically trying to follow this flow: https://developers.google.com/games/services/web/serverlogin but in Java, NOT Javascript. I am attempting to do this in an Android app and a desktop Java app.
1) Yes, in Android use GetServerAuthCodeResult although it is still marked as deprecated. It is the recommended way from Google and it seems they have only forgot to remove the deprecation annotation when releasing to general public.
2) For desktop applications you can follow the instructions here: https://developers.google.com/identity/protocols/OAuth2InstalledApp
Basically from your app you open the system browser (embedded webviews are discouraged) and make a https request to the https://accounts.google.com/o/oauth2/v2/auth endpoint. In the request you supply a local redirect URI parameter i.e. http://127.0.0.1:9004 (you should query your platform for the relevant loopback IP, and start a HTTP listener on a random available port). The authorization code will be sent to your local HTTP listener when the user has given consent or an error such as error=access_denied if the user declined the request. Your application must be listening on this local web server to retrieve the response with the authcode. You also have the option to redirect to a server URI directly claimed by your app, see docs on link above. When your app receives the authorization response, for best usability, it should respond with an HTML page, instructing the user to close the browser tab and return to your app. Also, if you want the Games-scope make sure you are using the https://www.googleapis.com/auth/games as scope in the request, example below, with line breaks and spaces for readability.
https://accounts.google.com/o/oauth2/v2/auth?
scope=https://www.googleapis.com/auth/games&
redirect_uri=http://127.0.0.1:9004&
response_type=code&
client_id=812741506391-h38jh0j4fv0ce1krdkiq0hfvt6n5amrf.apps.googleusercontent.com
Please note that I think you'll have to create and link an app of type other, in the Google Play Developer Console linked-app, for the localhost redirection to work. Use type Web if you plan to redirect to server URI directly, add your server URI to Authorized redirect URIs in the API Manager under section Credentials.
Browser screenshot:
There is finally a proper answer to part 1) of this question!
In the release notes of gms 10.2.0
https://developers.google.com/android/guides/releases#february_2017_-_v102
the new method of obtaining a server code is described. A good example of how to do this is provided here:
https://github.com/playgameservices/clientserverskeleton
I ended up updating Google's baseGameUtils to follow the example above.
Still not sure the proper way to do this for part 2) of the question, at the moment I am sending the token to the server which works but is probably unsafe.

Foursquare API usage: /venue/stats

I have couple of doubts regarding the usage and working of /venue/stats Foursquare API.
Q1. I would be using /venue/stats for getting information provided a venue id. So I have registered my app and got the client id and secret values. I went to Foursquare API endpoint and tried using /venue/stats api and I noticed a oauth_token generated automatically by FSQ so is this oauth_token the same token that I am required to use everytime I use this api ? Do I need to do the authentication steps mentioned ?
Q2. Try the api generates a link which has /simulate in the api URL. I assume that this is due to the fact that I am testing the API so FSQ has categorized such api calls as simulate calls. Please confirm my understanding. If this is so then whenever I use the api as mentioned i.e. /v2/venues/venue_id/stats I get an error JSON stating that I am unauthorized to view venue stats. Can you please tell me why ? If this is due to access_token issue then the same issue should have been with simulate call also ?
Hoping to get a reply soon.
Right underneath the API Explorer bar it says "OAuth token automatically added". You do not use this token. I am sure it is either temporary or created using your log in info if you are loggged in while using the API Explorer. You will still have to use the authentication process to get a valid access token. However, you can save this access token and use it again skipping the Auth process. An access token serves as a key unique to a user and app. Read more about it here: https://developer.foursquare.com/overview/auth
The simulate feature is used mostly for API calls that normally would require you to be a manager of the venue. There are certain calls that can not be done unless the app is by a user that is the manager or unless you make the call using an access token of a manager.

Android - Blogger (Best method of authentication - ClientLogin, etc)

I have been directed here by someone from the Google Blogger Developer group. My question is basically, what is the best way to authenticate with the Blogger service within Android.
Initially I used HTTPURLConnect in Java and sent requests and received responses, this worked fine when the correct username and password were provided, however, when an incorrect password was supplied rather than being given the response Error=BadAuthentication, Java threw a FileNotFoundException for https:// www.google.com/accounts/ClientLogin. My plan obviously being to parse the response given by Google (according to this list: http://code.google.com/apis/accounts/docs/AuthForInstalledApps.html#Response)
The second attempt I have used this library:
http://code.google.com/p/google-api-java-client/
However, here I get the following error (regardless of credentials):
02-11 16:57:46.515: INFO/dalvikvm(294): Could not find method
org.codehaus.jackson.JsonParser.getCurrentToken, referenced from
method
com.google.api.client.googleapis.json.JsonCParser.parserForResponse
If anyone could provide any insight at all into these errors OR a better way to implement an application where user on Android can login and then read/view/create/edit blog posts on Blogger using the GData API, I'd be hugely grateful.
Thanks,
Tim.
Try adding the google-api-client-1.2.2-alpha.jar (or the version of the API you are using) to the Build Path:
If you're using Eclipse:
Right Click on your project and go to Properties.
Go to Java Build Path in the left bar. Choose the Libraries tab and then "Add External Jar...".
Add the google-api-client-1.2.2-alpha.jar file and try to run again.

Problem facing fetching contacts from yahoo using open Social API

I was trying to get contact list from yahoo for POC. It was documented that the there is need to send a GET request to the URL with the user's ID and returns the contact list in XML format. I tried the same but facing the authentication message 401 from browser, normal console java application and from jsp too I guess I must try it using the open social API package. Can anybody please guide or suggest the solution for this problem if possible please post any code sample for any similar application in JAVA as I found most samples are unclear and in JSON only.
Thank You
Yahoo recently released an SDK for accessing Yahoo Social services via Java:
http://developer.yahoo.net/blog/archives/2010/07/yos_sdk_for_java.html
socialauth is a java library that allows importing contacts from Google, Yahoo, Hotmail and from other providers too.
http://code.google.com/p/socialauth/

Categories