I am currently using thus url to test the Facebook graph API and get my page feed to display it in my application:
DOC: https://developers.facebook.com/docs/graph-api/reference/v2.2/page/feed
https://graph.facebook.com/PAGE_ID/feed?access_token=APP_ID|APP_TOKEN
(all ID obfuscated but I can share them and create a new app id needed)
So, this feed is working fine and gives me the JSON output I need:
{
data: [
{
id: "blahblah",
from: {
category: "Industrials",
name: "blahblah",
id: "blahblah"
},
message: "blahblahhttps://www.blahblah.com/",
picture: "https://fbexternal-a.akamaihd.net/safe_image.php?blahblah.jpg",
link: "https://www.blahblah.com/",
name: "Home",
caption: "blahblah",
description: "blahblah.",
icon: "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
privacy: {
value: ""
},
type: "link",
status_type: "shared_story",
created_time: "2015-01-21T12:30:37+0000",
updated_time: "2015-01-21T12:30:37+0000",
shares: {
count: 2
},
likes: {
Proble is that I want to use exactly the same feature, but instead of parsing JSON, I would like to use Facebook SDK.
This is my current code:
new Request(
null,
"/PAGE_ID/feed?access_token=APP_ID|APP_TOKEN",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
Log.e("CVE","MESSAGE: "+response.getError().getErrorMessage());
}
}
).executeAsync();
But this method gives me some authentification issues.
I get the response: "Invalid OAuth access token signature"
Any idea what is wrong and if I have to use the HTTP request instead of Facebook SDK?
As #WizKid said above, NEVER put your app_token into a client app, that is a huge security hole. Only use user access tokens in your app. Alternatively, make the request server-side, and pass it on to your client app.
You're not using the Request methods properly. If you look at the documentation for the Request class (https://developers.facebook.com/docs/reference/android/current/class/Request/), you'll see that the second parameter is "graphPath", which should be only the "path" component of a URL. You are, however, including a query string as well, which is where things break. What you should do is something like this:
Bundle params = new Bundle();
params.putString("access_token", "YOUR_ACCESS_TOKEN");
new Request(
null,
"/PAGE_ID/feed",
params,
HttpMethod.GET,
...
Alternatively, you can also use the Session object instead (to get the user access token).
Related
I have been trying integerating master card gateway in android app using android sdk.
While i call update session API it always return me error. I have checked on their docs but nothing found about this error.
URL hit
https://mtf.gateway.mastercard.com/api/rest/version/57/merchant/{merchant id}/session/{SESSIONID}
Request params
{
"sourceOfFunds":{
"provided":{
"card":{
"nameOnCard":"raj",
"number":"123456789012345",
"securityCode":"0000",
"expiry":{
"month":"05",
"year":"21"
}
}
}
},
"device":{
"browser":"Gateway-Android-SDK/1.1.4"
}
}
Response
{
"error":{
"cause":"INVALID_REQUEST",
"explanation":"Directly providing cardholder data is not supported. Consider using a session or token."
},
"result":"ERROR"
}
first, you have to initialize new gateway
Gateway gateway = new Gateway();
gateway.setMerchantId("your merchant id");
gateway.setRegion(Gateway.Region.<your region>);
then make a new request to provide the card info, then use gateway.updateSession function as shown in the following link:
https://github.com/Mastercard-Gateway/gateway-android-sdk/wiki
My app uses Facebook Login Button of facebook-android-sdk.
It was working until last days, now on a graph request on a page's feed
Bundle parameters = new Bundle();
parameters.putString("fields", "id,icon,created_time,name,caption,description,message,link,full_picture,shares");
parameters.putString("limit", "50");
parameters.putString("locale", mLocale);
String pathPosts = path + "/posts";
GraphRequest request = new GraphRequest(
AccessToken.getCurrentAccessToken(), pathPosts, parameters, HttpMethod.GET,
new GraphRequest.Callback() {
#Override
public void onCompleted(
GraphResponse response) {
mResponse = response;
}
});
request.executeAndWait();
I get the OAuthException error
{Response: responseCode: 500, graphObject: null, error: {HttpStatus: 500, errorCode: 1, errorType: OAuthException, errorMessage: An unknown error has occurred.}}
UPDATE
Found that with limit lower-equal than 33 it works without errors
parameters.putString("limit", "33");
For another page's feed the limit must be lower-equal than 7 to work without errors
parameters.putString("limit", "7");
Question:
what is now the rule for the limit in a graph api request for page's feed?
Facebook Graph API has also got a Debug Mode. You need to pass an extra parameter debug=all in the REST API. It will give you the reason for the issue too in the response JSON if there is any issue.
Quoting Facebook documentation -
When Debug Mode is enabled, Graph API response may contain additional
fields that explain potential issues with the request. To enable debug
mode, use the debug query string parameter. For example:
GET graph.facebook.com /v2.3/me/friends
access_token=...&
debug=all
In your code, try changing this
String pathPosts = path + "/posts";
to this
String pathPosts = path + "/posts&debug=all";
Or
Add and an extra parameter "debug" "all" in your Bundle
and check what debug message you got
For more info on handling errors and debugging Graph API, see here - https://developers.facebook.com/docs/graph-api/using-graph-api/#errors
I'm requesting my me/albums with:
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/albums",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
parseAlbumResponse(response);
}
}).executeAsync();
Problem is that the response object only contains 3 fields:
{
"data": [
{
"created_time": "...",
"name": "...",
"id": "..."
},
...
Instead of all fields documented here. Sames goes for /{album-id}/photos:
{
"data": [
{
"created_time": "...",
"id": "..."
},
...
Instead of this.
It was working last time I've checked but all of a sudden this strange behaviour happened.
I've tested with Facebook Graph API and the result it's the same so I guess it's not a problem from my app.
I'm using 'com.facebook.android:facebook-android-sdk:4.7.0'.
Did Facebook changed something in the requests parameters?
EDIT:
As user luschn suggested:
Declarative Fields
To try to improve performance on mobile networks, Nodes and Edges in
v2.4 requires that you explicitly request the field(s) you need for
your GET requests. For example, GET /v2.4/me/feed no longer includes
likes and comments by default, but GET
/v2.4/me/feed?fields=comments,likes will return the data. For more
details see the docs on how to request specific fields.
So I had to change my requests to:
Web console:
me/albums?fields=name, cover_photo, count and /{album-id}/photos?fields=id, images
Java:
Bundle parameters = new Bundle();
parameters.putString("fields", "id, images");
Bundle parameters = new Bundle();
parameters.putString("fields", "name, cover_photo, count");
https://developers.facebook.com/docs/apps/changelog#v2_4
Search for "Declarative Fields" in the changelog, you have to specify the fields you want to get returned.
I have made a lot of combinations to get this working but I'm always getting an empty json, however in the Graph API Explorer it works very well, I'm using this statement to get the id of the albums from a X user:
SELECT aid from album WHERE owner = XXXXXXXXXX
it is returning (for example):
{
"data": [
{
"aid": "xxxxxxx_xxxx"
},
{
"aid": "xxxxxxxx_xxx"
}
]
}
in the drop down menu (where normally is Graph Api explorer selected) I have changed for my app, also I'm using the button "get access token" and selecting: "user_photos","friends_photos","user_friends" permissions,
but in my android app only I retrieve an empty json, (note: I have used another statement to recover user data (such as birthday) with this code, and works fine so code is correct, note2: I'm using the "user_photos","friends_photos","user_friends" permissions inside the app).
the code of the app (the fragment) is:
mynewbutton = (Button) view.findViewById(R.id.mynewbutton);
mynewbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View v) {
String fqlQuery = "SELECT aid from album WHERE owner = XXXXXXXXX";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
// params.putString("access_token", session.getAccessToken());
Request request = new Request(session,
"/fql",
params,
HttpMethod.GET,
new Request.Callback(){
public void onCompleted(Response response) {
//Log.i(TAG, "Result: " + response.toString());
}
});
Request.executeBatchAsync(request);
}
});
Possible the reason is cuz I'm not getting the "valid access_token" inside the app.
So it came some questions in mind:
1.-How do I get the access_token?
2.-Do I need to use the method getAccessToken()?
3.-If so, How do I integrate in my code?
4.-Is it necessary to change something in the Graph Api Explorer in order to get working well in the app?
5.- Am I missing something (a step or a piece of code for example)?
6.-In general, How do I get the aid from album inside my app just like in the Graph Api Explorer? thanks.
I'm developping a mobile application, which should connect to a web server. The application is written with jQM and simply imported in an android web view. I tried to solve this problem using the jStorage plugin, but it seems that it's impossible to share the local storage between the different pages. So I tried to implement this, but it does not work and continues sending null.
Here are my code samples:
Javascript:
function getToken(authCode) {
var jsonUrl = mainUrl + "/auth/authorizeToken?grant_type=authorization_code&client_id=bc89fb879a64eb8e422b94d5c39&client_secret=b5c2974b78f7f3f7aee2bed182&redirect_uri=redirection&code="+authCode;
$.ajax({
url: jsonUrl,
type: "GET",
dataType: "jsonp",
success: function(data) {
localStorage.setItem( "access_token", data.access_token);
localStorage.setItem( "refresh_token", data.refresh_token);
localStorage.setItem( "logged", "true");
}
});
}
function valTokens() {
access_token = localStorage.getItem("access_token");
refresh_token = localStorage.getItem("refresh_token");
}
After that the values are set to null. The .java files are the same as in the sample from the link given.