Facebook returns #access_token - java

I am using Java Scribe + Spring MVC to access Facebook authentication API.
However, the URL with the access token I am getting back from Facebook is in this format:
/facebookCallback#access_token=[long chunk]&expires_in=5028
As you can see, the access_token is preceded by a #, which disallows me from obtaining the access_code as a normal parameter.
Is there any reason why Facebook is appending the # instead of a ?

var hash = document.location.hash;
I think you mean Javascript , and not Java Scribe ?

you are probably using the callback parameter which is designed for the JS library. Make sure you are not sending an incorrect parameter for "type".

Turns out that it probably was caused by my school network. I tried the exact same code both in school and at home and got different results (school - error, home - correct).
The problem solved by itself the next day in school so I won't be able to find out exactly why. Thanks to those who helped.

Related

Retrofit, IGDB Api - How to correctly pass Api Key?

I'm trying to make an query on the internet game database (IGDB) Api using retrofit. In the past, when I used other Api, such as the movie database (TMDB), the api-keys were always passed in as a query, so the interface would look something like this.
#GET("/3/movie/popular")
Call<MovieResults> getPopularMovie(
#Query("api_key") String apiKey,
#Query("language") String language,
#Query("page") int page
);
But with IGDB, I think they want me to pass in the api-key as a Header (I'm not 100% sure, please correct me if I'm wrong). I've never passed an api-key through a header before, so with some guesswork, following is what my interface looks like.
#Headers({
"Accept: application/json",
"user-key: b5bd50####################8b2"
})
#GET("/games")
Call<List<Game>> getGame();
Problem is, when I make the call, although the call ends up in onResponse, the response.body is always null.
So, I ran the code in de-bug mode, and i found this message:
response = Response{protocol=http/1.1, code=401, message=Unauthorized, url=http://v2000.igdb.com/games/}
I don't know what this means, but I am guessing that it isn't recognizing an authorised api-key?
Another interesting anomaly is that, the base url I pass in is:
"https://api-2445582011268.apicast.io/"
I don't know how that ended up being:
http://v2000.igdb.com/
If anyone have any experience with IGDB, please give me some help, will really appreciate it.
I have used this api with JAVA and i can confirm that you should send the API key in the header, so what you have done looks to be correct.
The base url you are getting is also wrong, try using https://api-endpoint.igdb.com/, it is the recommended url.
I can also recommend you to try the api using Postman, it is an excellent tool for testing.
If you are using java you might want to try their java wrapper

Google books api always returns nothing

I am trying to use Google books API but for any request I receive totalItems = 0.
I've tried to send the request in chrome, for example:
https://www.googleapis.com/books/v1/volumes?q=flowers+inauthor:keyes&key=MY_KEY
Also I've tried the approach, described here:
https://github.com/google/google-api-java-client-samples/blob/master/books-cmdline-sample/src/main/java/com/google/api/services/samples/books/cmdline/BooksSample.java
And for any query with any parameters I always receive nothing:
{
"kind": "books#volumes",
"totalItems": 0
}
I generated key using developer console: https://console.developers.google.com and selected option Api Key.
I will appreciate any help with this issue.
Thanks in advance!
As I've understood, the problem is in my country(Belarus). Looks like Google Books APi doesn't work in Belarus. Problem can be fixed by using VPN.

Getting, (#803) Some of the aliases you requested do not exist error

When i am trying to get data from facebook using graph api, i am getting this error,
{"error":
{"message":"(#803) Some of the aliases you requested do not exist: 124186682456_10151302011177457&access_token=REMOVED_ACCESS_TOKEN",
"type":"OAuthException",
"code":803}}
Can anyone help me in how to solve this problem.
Thanks in advance...
If that is an accurate representation of the error you're receiving, you're incorrectly appending the access token after a & character instead of a ?.
You need to use ? for the start of the query string, and & to separate the parameters inside the query string
e.g.
https://graph.facebook.com/124186682456_10151302011177457?access_token=ACCESS_TOKEN
Placement of access_token parameter immediately after ? has nothing to do with issue...
It could be that your URL is littered with %20 or similar stuff.
I got this error when trying a test example from Facebook API documentation, at first I have read highest voted answer, but moving access_token parameter immediately after ? didn't work, I then inspected URL more closely and found some of encoded spaces %20 that were stuck to parameter fields and some others, removing which fixed the issue.
try following URL (just replace access_token parameter with yours)
https://graph.facebook.com/search?type=place&fields=name,checkins,picture&q=cafe&center=40.7304,-73.9921&distance=1000&access_token=[YOUR_ACCESS_TOKEN]
If it works look for problem in Facebook parameter names
Hope this saves you some time.
This was happening for me with the Instagram content publishing API which also rides off the facebook graph api. It seems to happen when something is wrong with the API URL you are trying to send to Facebook via GET request.
In my case, something was happening in my code causing the user_id and access_token to not be passed to the URL before trying to query the graph API.

Using Facebook App Access Token (Pipe character in URL)

I am completely stumped by this. I have the following Facebook App Access Token registered for my app:
|
And then I try to GET the following URL: (Fake token underneath)
https://graph.facebook.com/<user-id>/likes?access_token=<number>|<hash>
String accessToken = "258443224256787|dsK3fffe7g-rejponkVlfwef3GenVng6Y";
WS.url("https://graph.facebook.com/" + socialUser.id.id + "/likes?access_token="+accessToken)
accessToken = "258443224256787" + URLEncoder.encode("|") + "dsK3ks7g-dsK3fffe7g-rejponkVlfwef3GenVng6Y";
I get the following error message:
{"error":{"message":"An access token is required to request this
resource.","type":"OAuthException","code":104}}
When I use it in the Graph API explorer tool however, I get no errors! I think the problem might be that I don't know how to use the pipe symbol in my URLs (tried Googling for hours without success - attempted URLEncoder.encodre to no avail).
Help please! :-)
(I'm using Java Play! 2)
Edit I should say that when I debug my link I get: "%7C" instead of pipe, due to the URLEncoder.
Edit 2 It also works when I post the URL directly into the browser.
Edit 3 Added URLEncoder-code
Turns out that WS.url() didn't accept my query parameters unless I used url().setQueryParameters() which solved the problem. :-)

FB is sending me a non-URL safe code

FB is sending me a non-URL safe code. While implementing the oauth authentication, FB is sending me a code parameter that is non-url safe.
When i authorize the app i am getting the code parameter with the below value which is not url safe.
AQBQnGZgFNv5EcIB9hZI20GcUgBWru7TE-p_G5NB2HQLX87fyc463aM0BIAiBg_PwRiIuyo0KS1vrDLOLB_SQ0goY31RrNYtZ23lOeaOkGzztarMYH8bJpSYjFOgiXbPhcP6h9YCsizekmcbLpPX_3F7qhsZOLM37UGI7QysvyYOvptpgJ-fm5t-eSViIU_CQH8jTPcQu3BylUVIXS0cEt5T#___=_
When FB is redirecting the control to the my url which is a java web application, i tried to get the code parameter using the code "request.getParameter(CODE)" But i am getting only
AQBQnGZgFNv5EcIB9hZI20GcUgBWru7TE-p_G5NB2HQLX87fyc463aM0BIAiBg_PwRiIuyo0KS1vrDLOLB_SQ0goY31RrNYtZ23lOeaOkGzztarMYH8bJpSYjFOgiXbPhcP6h9YCsizekmcbLpPX_3F7qhsZOLM37UGI7QysvyYOvptpgJ-fm5t-eSViIU_CQH8jTPcQu3BylUVIXS0cEt5T
without #___=_
so i am not able to continue further. But i manually add it to the parameter to fetch the access token it is working fine.
Why is this happening? Please help me.
i think this is signed_request code.
You doesn't need the #_=_ trail to get further, it's not a part of signed_request or code for OAuth2. If you can proceed to further steps it's something other that this.
Once you get code passed to redirect_uri URL you can continue with authentication:
In order to authenticate your app, you must pass the authorization code and your app secret to the Graph API token endpoint - along with the exact same redirect_uri used above - at https://graph.facebook.com/oauth/access_token.
https://graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&
client_secret=YOUR_APP_SECRET&code=THE_CODE_FROM_ABOVE

Categories