I have created an Android Application in that I want to get Facebook Events using Graph API.
So now I can get only Admin and Developer's events, I can't get other users events.
So what can I do for getting other users events.
My Code is:
new Request(
session,
"/" + user.getId() + "/events",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
Log.v("response", "event : " + response);
}
}
).executeAsync();
Thanks.
Have a look at the facebook docs. Your application need to go through review to be able to request the user_events permission to non-admins/developers/testers:
https://developers.facebook.com/docs/facebook-login/review/overview
Related
I want to share an image on a Facebook page of mine. But I couldn't figure out how to do this step by step. And couldn't find step by step guide for this.
This is my code to share an image on a page
Bundle params = new Bundle();
String nameText = name.getText().toString();
String tags = engine.implodeTags(tagsList);
String textText = text.getText().toString();
params.putString("caption", nameText + "\n\n" + textText + "\n\n" + tags);
params.putString("url", imagesList.get(mainImageSelected).getImageUrl());
params.putString("access_token", "{access token here}");
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{page_id here}/photos",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
if(response.getJSONObject()!=null) {
Log.d("qwe", response.getJSONObject().toString());
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(activity, "Shared on facebook", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}
});
}
else{
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(activity, "Error", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}
});
}
}
}
).executeAsync();
It works if I put access token by hand. I am getting access token here
https://developers.facebook.com/tools/explorer .
But after some time this access token is not working any more. So I need to get new access token.
How to get PAGE access token from android itself? Via user login button of facebook sdk?
https://developers.facebook.com/docs/facebook-login/access-tokens
Please help.
Easily if you use facebook SDK to do that. read at here https://developers.facebook.com/docs/sharing/android
You need to get Permanent access token to share images on your Page. To get that you need to follow steps written here.
facebook: permanent Page Access Token?
I ma trying to read facebook event's details from an ANdroid application by using this code :
new Request(
session,
"me/events/created",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
System.out.println("Result: " + response.toString());
}
}
).executeAsync();
but I m always receiving a ampty response :
Result: {Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[]}}, error: null, isFromCache:false}
Although when i tried the Graph API Explorer https://developers.facebook.com/tools/explorer i get the right list !!!!
Have you configured the correct permissions for your app? To get the User's Events, you need to aquire the user_events permission upon login.
See https://developers.facebook.com/docs/graph-api/reference/v2.0/user/events/#readperms
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'm developing my first Android App using Parse and Facebook, so I'm pretty new to it.
I'm trying to retrieve the User's Friend List with Request.newMyFriendsRequest() but it gives me an empty list when testing with real users.
As far as I know, with Graph API v2.0 this request only will return the set of the person's friends who also use the app.
For that purpose I created a fake Fb profile, I became friend with him in Facebook with my real profile, installed my app, registered with ParseUser and Linked with Facebook using ParseFacebookUtils.link with both profiles, but the Request returns an empty list of friends.
I've created several Test Users in Facebook's App dashboard, and simulated several friendships between them. I made the same process in my app (register with parseUser, link with ParseFacebookUtils.link) with two of them, and the list users.size() returns 2 friends as expected.
Why it doesn't work with my actual profile and the fake one (which is like any other real one)??
This is how I'm linking profiles:
List<String> permissions = new ArrayList<String>();
permissions.add("public_profile");
permissions.add("user_friends");
ParseFacebookUtils.link(currentUser, permissions, MainActivity.this, new SaveCallback() {
#Override
public void done(ParseException ex) {
if (ParseFacebookUtils.isLinked(currentUser)) {
Log.d(TAG, "Woohoo, user logged in with Facebook!");
Toast.makeText(getApplicationContext(), "Facebook succesfully linked", Toast.LENGTH_LONG).show();
}
if (ex != null) {
Log.d (TAG, ex.getLocalizedMessage() + "\n + Exception Code: " + ex.getCode());
}
});
And this how I Request friends:
Request.newMyFriendsRequest(ParseFacebookUtils.getSession(), new GraphUserListCallback() {
#Override
public void onCompleted(List<GraphUser> users, Response response) {
Log.d(TAG, "Request Completed!! " + response.toString() + "----" + users.size());
if (users != null) {
List<String> friendsList = new ArrayList<String>();
for (GraphUser user : users) {
friendsList.add(user.getId());
}
}
}
}).executeAsync();.
But I can't figure out how to get the friends list of a real user. With my profile it should return 1 friend who is also registered using the app being developed...
I got an empty array because of the following:
- This will only return any friends who have used (via Facebook Login) the app making the request.
Please note!
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.