Android Facebook SDK - Get user events - android

i've being able to login and get the user infos from the api with this code:
Facebook facebook = new Facebook("XX");
AccessToken token = AccessToken.createFromExistingAccessToken("XX", new Date(facebook.getAccessExpires()),
new Date(facebook.getLastAccessUpdate()),
AccessTokenSource.FACEBOOK_APPLICATION_NATIVE, Arrays.asList(permissions));
Session.openActiveSessionWithAccessToken(getActivity(), token, callback);
session = Session.getActiveSession();
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
Object proper = user.getFirstName();
System.out.println(proper);
}
});
I'm using this fixed tokens cause its always come from the same user as some sort of a host but i need to get the user events and havent seen any documentation that shows how to do it, does anyone have any idea of how to get the user events that he created?
thank you!

I've managed to achieve what i want using a FQL Query with this code:
String fqlQuery = "SELECT eid, name, pic, creator, start_time FROM event WHERE eid IN (SELECT eid FROM event_member WHERE uid='XX' and rsvp_status='attending')";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Request request = new Request(session, "/fql", params, HttpMethod.GET,
new Request.Callback() {
#Override
public void onCompleted(Response response) {
System.out.println("Result: " + response.toString());
}
});
Request.executeBatchAsync(request);

Related

Facebook SDK 4.5.0 returning wrong user id in android

In my App i am integrating facebook SDK 4.5.0.
To fetch details of user I am using method
GraphRequest request = GraphRequest.newMeRequest
In user json response i am getting wrong user id.
In case of IOS for same application and same user i get correct userId.
Can anyone help me to solve this?
This is my Code to fetch user details:
GraphRequest request = GraphRequest.newMeRequest(com.facebook.AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject user, GraphResponse response) {
if (user != null) {
doLoginFb(user);
}
}
});
request.executeAsync();
After V2.0API user id is "app-scoped" so the id can be different for same user on different apps.
You can refer to the documentation here for more details.
It also says this :
No matter what version they originally used to sign up for your app,
the ID will remain the same for people who have already logged into
your app. This change is backwards-compatible for anyone who has
logged into your app at any point in the past.
If you're not mapping IDs across apps, then no code changes should be required.
Get some public profile of user:
Bundle params = new Bundle();
params.putString("fields", "id,name,email");
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me",
params,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
try {
Log.e("JSON",response.toString());
JSONObject data = response.getJSONObject();
//data.getString("id"),
//data.getString("name"),
//data.getString("email")
} catch (Exception e){
e.printStackTrace();
}
}
}
).executeAsync();

How can I upload photo to facebook album from android app using following graph API?

I am new to android development. I am trying to post photo from an android app to user's facebook album. I added following code after I logged in the user with permissions "user_friends"
new GraphRequest(
MainFragment.mAccessToken.getCurrentAccessToken(),
"/me/photos",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
// This is my code for user login at app start
post = (Button)view.findViewById(R.id.button1);
mLoginManager = LoginManager.getInstance();
mLoginManager.registerCallback(mCallbackManager, mCallback);
mLoginManager.logInWithReadPermissions(this, Arrays.asList("user_friends")); //user_friends // publish_actions
Please guide me
I did a mistake .. Firstly, my question was incomplete .. I have found the issue .. Following seems to be working.
MainFragment.mLoginManager.logInWithPublishPermissions(this, Arrays.asList("publish_actions"));
Bundle params = new Bundle();
params.putString("url", "http://www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jpg");
/* make the API call /
new GraphRequest(
MainFragment.mAccessToken.getCurrentAccessToken(),
"/me/photos",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/ handle the result */
Log.d("MainFragment:", "onCompleted mAccessToken = " + MainFragment.mAccessToken.getCurrentAccessToken());
}
}
).executeAsync();

access facebook page information

I want to get facebook page about, description, location, basic info etc. I have got the access token for page. I am getting likes of page like this:
public void getLikes (String id,final TextView likes,final int position)
{
Session session = Session.getActiveSession();
Bundle params = new Bundle();
params.putString("id", id);
params.putString("fields", "likes");
Request request = new Request(session, "search", params, HttpMethod.GET, new Request.Callback() {
#Override
public void onCompleted(Response response) {
try {
JSONObject res = response.getGraphObject().getInnerJSONObject().getJSONArray("data").getJSONObject(0);
if (res.length()>1){
likes.setText(String.valueOf(res.getInt("likes")));
Preferences.data.getData().get(position).setLikes(String.valueOf(res.getInt("likes")));
}
else {
Preferences.data.getData().get(position).setLikes("No Likes");
likes.setText("0");
}
} catch (Exception e) {
}
}
});
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
}
If I add more parameters in bundle, I get the value of last parameter added, what should I do. Facebook's documentation about graph api is not much clear.
This isn't an issue specific to the API, you're just only using one field of the response (.getJSONObject(0))
if you request multiple fields you need to look at each of them, currently you're only fetching the first

Friends email issue while getting from facebook api

I'm trying to get friends email addresses using facebook api like that
private static final List<String> PERMISSIONS = Arrays.asList("publish_actions","read_stream", "email", "user_about_me", "friends_about_me", "friends_notes");
String fqlQuery = "SELECT uid, name, pic_square, contact_email FROM user WHERE uid IN " + "(SELECT uid2 FROM friend WHERE uid1 = me())";
Bundle params = new Bundle();
params.putString("q", fqlQuery);
Session session = Session.getActiveSession();
Request request = new Request(session, "/fql", params, HttpMethod.GET, new Request.Callback()
{
public void onCompleted(Response response)
{
Log.e("log_tag", "response: "+response);
}
});
Request.executeBatchAsync(request);
But I cant get success for email but ya i am getting other values. Any one have idea about that?
I also need to get contact numbers of friends. Is it possible? Also guide me for that.
Thanks
According to the official docs:
There is no way for apps to obtain email addresses for a user's friends.
For more details: Email Permissions

How to get json response from facebook fql query in android

I am using an fql query to get the json response.I am new to this fql execution process.can I know in detail how to execute this query.I have seen some Listener class is using while getting the response,
SELECT likes.user_likes FROM stream WHERE post_id ='XXXXXXXXXXXXX_XXXXXXXXX'
Do I need to have anything to execute this and get the response?
Thanks in advance
private void doFQLQuery()
{
//get the active facebook session
Session session = Session.getActiveSession();
//create the fql query
String fqlQuery = "SELECT likes.user_likes FROM stream WHERE post_id ='XXXXXXXXXXXXX_XXXXXXXXX'";
//create a bundle for the parameters(your query)
Bundle params = new Bundle();
params.putString("q", fqlQuery);
//setup the request
Request request = new Request(session, "/fql", params, HttpMethod.GET, new Request.Callback()
{
public void onCompleted(Response response)
{
//when the request is completed output the results to the log
Log.i(TAG, "Result: " + response.toString());
}
});
//execute the request
Request.executeBatchAsync(request);
}
You can use this code to execute an fql query and get the response. Whatever processing you want to to do on the results should be done in the onCompleted method.

Categories

Resources