I'm just starting out with android development and using the Facebook SDK. I have followed online tutorials and successfully made an app that logs into facebook and now im trying to make an app that creates a new activity showing the profile picture of the user after logging in.
I'm trying to follow the facebook documentation for using the SDK however it is rather vague and I was hoping to find a better example. All I can find is the following example code:
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{user-id}/photos",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
I'm fine with all the access token stuff but I have no idea how to handle the result. How can save the images from "response" and how can I display these images in a new activity? A link to a relevant example would be really helpful. I've been looking for hours and found nothing related recent versions of the SDK.
Related
I am just new to Android Application and trying my hands on implementing Facebook login within my app. Successfully implementation of login but logout causes some trouble.
The first time I logged in it requested for my details and then signed in.
Next time I do the same it no more asks for my details, by default it logs me in with account.
What if I want to sign in with different user?
I have searched the net for solution and found out that -
- I cannot use Session as they were available only till Facebook SDK 3.X.X not for SDK 4.X.X
- I have tried calling LoginManager.getInstance().logOut();
(But I still have doubts where to use it.)
- I have also tried
new GraphRequest(AccessToken.getCurrentAccessToken(),"/me/permissions/", null, HttpMethod.DELETE,
new GraphRequest.Callback(){
#Override
public void onCompleted(GraphResponse graphResponse) {
LoginManager.getInstance().logOut();
}
}).executeAsync();
and I have also tried doing this :
` AccountManager am = AccountManager.get(context);
Account[] localAccounts = am.getAccounts();
for (int i=0; i<localAccounts.length; i++){
if (localAccounts[i].type.equals("com.facebook.auth.login")){
am.removeAccount(localAccounts[i], null, null);
}
}`
So it'll be really great if somebody could guide me properly on how to carry out a successful logout operation on Facebook, I'll be highly obliged.
Thanks in advance :)
The SDK will use either of two options to let the user log in to your app on Android:
using the native login dialog (which is powered by the Facebook app that is installed on the device)
using a webview-based dialog if the Facebook app is not installed on the device.
Both options depend on you being signed into Facebook in another app (your browser/your native Facebook app).
If you want to log into your app as a different user (there is really no need, because android system user profiles should be considered personal and individually owned), you need to go to the app you use for Facebook (native Facebook app/browser) and switch to a different profile there. After that you should be able to log into your app with that other profile.
Other than that, it is not your app's job to log people out of their Facebook.
my problem is how to share highscore in facebook for my app.
I have an android game written with eclipse and I can correctly connect through Facebook using facebook SDK and facebook LoginButton.
I need to have all of the game player's high scores and compare them and find the 10 best scores of all of the users. I searched a lot and I found that using graph API would help me to do that. I used this code which was in https://developers.facebook.com/docs/graph-api/reference/v2.4/user/scores in eclipse where I wanted to share the scores:
Bundle params = new Bundle();
params.putString("score", "the score I get from the game");
new GraphRequest(AccessToken.getCurrentAccessToken(), "/me/scores",
params, HttpMethod.POST, new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
// TODO Auto-generated method stub
}
}).executeAsync();
but as I go to graph API explorer, I am just able to get my own score:
/me/scores
but I need to have all of the user's scores and compare them with each other. any idea if you have to help me in this kind of sharing. and aware me if the graph API is not a good way for this case.
I have checked similar questions but I didn't find a clear way.
first, I'am sorry. i can't english well.
i have a problem in facebook sdk.
now i am developing login with facebook sdk.
and logout too.
but i can't find unlink api between my-app and facebook.
for example, some user using my app do not want to use my app more.
so he needs to ban me(or my app) in order to protect his data on facebook.
do you understand me? T.T please help me.
following flow is when the user unlinks the app himself directly.
but i want to do this in my app menu with login, logout, etc.
Menu Flow : (in facebook app settings) Apps -> Logged in with Facebook -> (choice a app) -> Remove App
FB.api("/me/permissions","DELETE",function(response){
console.log(response); //gives true on app delete success
});
You need a active access token of user to do this
Using Facebook sdk
new Request(
session,
"/me/permissions/{permission-to-revoke}",
null,
HttpMethod.DELETE,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
Hello Friends
I am trying to get facebook album of a user . Problem is that it is returning albums for the user who is created the facebook app or who is the admin of that application .
For rest of the users it is returning the empty array
new Request(session, "/me/albums", null, HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
System.out.println("Responce "
+ response.getGraphObject());
}
}).executeAsync();
This work for me because i have create a facebook app and for the rest of the users it is not returning the data. Please let me know how to resolve this.
Thanks
Amit
When your application is in sandbox/development mode you can not perform any api call for other user. To test your for other user, add the user as a tester, developer or admin. See details here
Since you probably ask for the user_photos permission already (else it would not work for the admin), there are two possible problems why it does not work for other users:
Your App is in not set public. Go to the "Status & Review" tab of your App settings and make sure that checkbox on top says "YES".
Most permissions (like user_photos) need to get reviewed by Facebook before you can use them for any other user: https://developers.facebook.com/docs/apps/review/login
In my application I have one expandable list view which displays Facebook messages.
When a user clicks the list view then a child view opens in that I have a button called Like. By clicking the Like button the original message should be liked in Facebook
One important thing is that it should not ask login details from the user. I searched a lot on the web but I find any good tutorial.
I don't have any basic idea of Facebook. Please provide me with some suggestions of how to do it.
Thanks
Well, if you want to like Facebook messages, you need to ask a permission for that with the Facebook SDK :
https://github.com/facebook/facebook-android-sdk
So Basically, you can do SSO with Facebook SDK, he will just ask for the permission needed if the user is already logged on his Facebook application.
Take a look at the sample on the Android SDK Facebook on the link above.
When you have the "like" permission (publish_stream), you can do it like that :
Request likeFacebook = new Request(Session.getActiveSession(), fBPostId + "/likes", null, HttpMethod.POST, new Request.Callback() {
#Override
public void onCompleted(Response response) {
// analyse your response
}
});
Request.executeBatchAndWait(likeFacebook);