Currently I call requestNewPublishPermissions to request the publish_stream permission.
Is there a way for me to see if the user has already authorized that permission so I don't need to ask it again?
I thought Session.isPublishPermission("publish_stream") might be that, but it doesn't seem to match the expected behavior.
To check if the user has already authorized a permission, you have to call the API:
\GET /me/permissions
You'll get the response in the format:
{
"data": [
{
"installed": 1,
"basic_info": 1,
"public_profile": 1,
"publish_stream": 1,
"user_notes": 1,
"user_friends": 1
}
],
}
If this have the "publish_stream": 1 permission that means the user has authorized the app to publish on his behalf.
Code (if using android SDK)-
new Request(
session,
"/me/permissions",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
Related
I'm trying to get the name of a user from his user ID.
on this link they say that we can do it from a simple HTTP request like that:
http://graph.facebook.com/4
But it seems that this method is outdated because i cant get anything because:
"An access token is requir…o request this resource."
Anyway i tried using their documentation about the graph api on Android and i did it like that:
GraphRequestAsyncTask request1 = new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/"+id1+"/name",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
name1.setText(request1.toString());
But on the name1 TextView i get a message that tells me
{RequestAsyncTask:
connection:null,requests:[{Request:
accesToken:{AccessToken
token:ACCESS_TOKEN_REMOVED permissions:
[public_profile]},
graphPath:/100017723671435/name, graphObject: null,
httpMethod:Get,
parameters:Bundle[{}]}]}
I don't really understand how to do, i have a bunch of facebook ID's on my database and i just want to get the name from the ID, to display it on the screen.
The current user of the app is not the profile which i want to get the infos!
EDIT: It seems i misunderstood the /*handle the result*/ commentary, i made this line like that:
name1.setText(response.toString());
But i have still an error on my TextView:
{Response:
responseCode:400,
graphObject:null,
error: { HttpStatus:400,
errorCode: 2500,
errorType: OAuthException,
errorMessage: Unknown path components: /first_name }}
So it seems i don't use the Graph Paths properly. I'm still looking on the doc and on Google, if i find the answer i'll give the code!
Ensure that you are logged in with read permission.
If you are logged in you can try with:
GraphRequest.Callback gCallback = new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
Log.d(TAG, "onCompleted: ");
if (response != null && response.getJSONObject() != null && response.getJSONObject().has("first_name"))
{
try {
name1.setText(response.getJSONObject().getString("first_name"));
} catch (JSONException e) {
Log.e(TAG, "onCompleted: ",e );
}
}
}
};
new GraphRequest(AccessToken.getCurrentAccessToken(),"/me?fields=id,name,gender,email,first_name,last_name", null,HttpMethod.GET, gCallback).executeAsync();
If you have a problem with login, maybe this link can help you.
I am creating an application. I want to access the friends list form Facebook in my app, but i am unable to access the Facebook friends list in my app. All others thinks are accessible, only friend list is not accessible. I have an old app id in which i access all the friends but in my new app id i am unable to access the friend list. In my app, I mention the following permissions:
1. Public_Profiles
2. basic_info
3. user_photos
4. user friends
5. read_friendslist
if any others permissions are needed then please let me know.
You new app is using API v2.0 and in API v2.0 you can not get all friends. /me/friends will only return friends that are also using the app.
There are some new APIs added in v2.0 that you may be able to use: taggable_friends, invitable_friends and social context.
I am getting friends list in two ways:
`Session activeSession = Session.getActiveSession();
if (activeSession.getState().isOpened()) {
Request friendRequest = Request.newMyFriendsRequest(activeSession,
new GraphUserListCallback() {
#Override
public void onCompleted(List<GraphUser> users,
Response response) {
UsefullData.Log("Response : " + response.toString());
UsefullData.Log("Friends list" + users);
//setUserFriendsList(users);
}
});
Bundle params = new Bundle();
params.putString("fields", "id, name, picture");
friendRequest.setParameters(params);
friendRequest.executeAsync();
}`
Request friendRequest = new Request(
activeSession,
"/me/friends",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
UsefullData.Log("Friends Response : " + response.toString());
//setUserFriendsList(response);
}
}
);friendRequest.executeAsync();
Note: set custome permission "user_friends" in your session.
both codes are working at my end. I hope it will help for you.
I have downloaded facebook-android-sdk-3.14.1.zip and am trying to get the examples working. I get stuck on the FriendPickerFragment that never returns a list of friends. I can log onto Facebook ok (again using the Facebook code), both using the 'Scrumptious' example and my version of it by followiing https://developers.facebook.com/docs/android/getting-started
I found that my requests were only going with public profile permission e.g.
{Session state:OPENED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[public_profile]}, appId:520510648055719}
I took code from Facebook friend picker SDK sample not working Android, that would add the user_friends permission and see that Session was now:
{Session state:OPENED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[public_profile, basic_info, user_friends]}, appId:520510648055719}
When I traced the code down to RequestAsyncTask.doInBackground the values of requests in :
#Override
protected List<Response> doInBackground(Void... params) {
try {
if (connection == null) {
return requests.executeAndWait();
} else {
return Request.executeConnectionAndWait(connection, requests);
}
} catch (Exception e) {
exception = e;
return null;
}
}
is
{Request: session: {Session state:OPENED, token:{AccessToken token:ACCESS_TOKEN_REMOVED permissions:[public_profile, basic_info, user_friends]}, appId:520510648055719}, graphPath: me/friends, graphObject: null, restMethod: null, httpMethod: GET, parameters: Bundle[{fields=id,name,picture.height(75).width(75)}]}
and I see as a response in onPostExecute(List result) :
[{Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[]}}, error: null, isFromCache:true}]
Could there have been some caching problem earlier that I need to clear first? If so how do I do that?
I have read that Facebook has changed security recently. I have create my Facebook TestUI 'app' and entered the hashKey (I assume all is ok as I can log into Facebook successfully)
Is there something else I should be looking at?
Looking for any and all wisdom on this.
Thanks
Eric
With Graph Search v2.0, requests for a user's friends will only return a list of friends that also use your app (including the samples), and the user_friends permission must be requested as a special permission. There doesn't appear to be a true way around this, though you can search for things like "taggable_friends" using something like:
new Request(
session,
"/me/taggable_friends", //instead of "/me/friends"
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}).executeAsync();
from Facebook Graph Reference.
I want to get a list of a users albums names and ids. You need to add the permission users_photos for this.
I created a method called fetchAlbums, and in it I am requesting additional permissions. But by the time the permissions dialog pops up, the rest of the method has already executed (without the needed permissions!).
Whats the best way to do this, add the permissions in the onCreate of the Activity?
private void fetchAlbumsFromFB() {
Session session = Session.getActiveSession();
// make a new async request
Bundle params = new Bundle();
params.putString("fields", "id, name");
new Request(
session,
"/me/albums",
params,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
// use response id to upload photo to that album
//errText.setText("New Album created response: " + response.toString());
//need to get the newly created album ID.
try{
JSONObject graphResponse =response.getGraphObject().getInnerJSONObject();
Toast.makeText(getApplicationContext(), "Albums " + graphResponse.toString(), Toast.LENGTH_LONG).show();
}
catch (Exception e) {
e.printStackTrace();
albID = null;
}
}
}
).executeAsync();
}
It's better to ask for user_photos permission at the starting point, when the user is authenticating the app the first time.
Since it's not an extended/publish permission, it will be asked along with the basic permissions and user wont bother too; else user will see the permission dialogs again and again that could frustrate him.
I guess, in that case this problem will be solved too.
I have a Bitmap image in my Android application and I need to upload it to the logged user's wall, including a caption message.
I've already implemented the Login button that (should) set-up the Session and, after a check with session.isOpened(), I call the method newUploadPhotoRequest(session, image, callback).
The problem is that the picture is never uploaded. Apparently, the login works because session.isOpened() return true after the user clicked on the Login Button. This means that API key, debug/release key hashes and all those stuffs are correct.
Instead, the callback of the upload method return this response:
{Response: responseCode: 200, graphObject: null, error: {HttpStatus: -1, errorCode: -1, errorType: null, errorMessage: null}, isFromCache:false}
Following: the code snippet behind the Activity (called FacebookActivity) that should upload the Bitmap.
private void startSending() {
((LinearLayout)findViewById(R.id.LoginLayout)).setVisibility(View.INVISIBLE);
((LinearLayout)findViewById(R.id.SendingLayout)).setVisibility(View.VISIBLE);
Request photoRequest = Request.newUploadPhotoRequest(Session.getActiveSession(), picture, new Request.Callback() {
#Override
public void onCompleted(Response response) {
Toast toast;
if(response.getError() == null) {
toast = Toast.makeText(getApplicationContext(), getString(R.string.ask_facebook_sent), Toast.LENGTH_LONG);
}
else {
// ERROR!
toast = Toast.makeText(getApplicationContext(), "Error! " + response.toString(), Toast.LENGTH_LONG);
}
toast.show();
finish();
}
});
Bundle requestParams = photoRequest.getParameters();
requestParams.putString("message", message);
photoRequest.setParameters(requestParams);
Request.executeBatchAsync(photoRequest);
}
Some considerations:
The picture is valid and visible
Facebook SDK is at the latest version (3.0.2)
I'm working on real device, with API level 8
In the Facebook Dev's Application page, I set the fields this way:
Package Name: com.ale.upmap (the app's namespace)
Class name: com.ale.upmap.FacebookActivity
Application has photo_upload permission enabled
Question: do I need to set permissions on the code too? Isn't it automatic? Also I didn't see any examples that use this method...