How can i get a friends last status in Facebook ?
Request r = Request.newMyFriendsRequest(
ParseFacebookUtils.getSession(), new GraphUserListCallback() {
#Override
public void onCompleted(List<GraphUser> users,
Response response) {
if (users != null) {
pb.setVisibility(View.GONE);
ll.startAnimation(fadein);
ll.setVisibility(View.VISIBLE);
friends = users;
f = new ArrayList<String>();
for (int i = 0; i < users.size(); i++) {
f.add(users.get(i).getName());
}
loadRandom();
}
}
});
Bundle params = r.getParameters();
params.putString("fields", "name,id,gender");
r.setParameters(params);
r.executeAsync();
I am using this code, but how can i get their status ?
You could use
params.putString("fields", "name,id,gender,statuses.limit(1)");
to achieve this. Remember that you need the "user_status" permission to do this.
Related
is it possible to get all of my users without adding them to through contacts. My problem is that I store users in Firebase and they can have invisible profile. I need to get only users with visible profiles. How can I achieve this?
Thanks
You can use the below method code for getting all the user users .You need to pass the users of set type then you will get the response in if(!TextUtils.isEmpty(response)){
public String postUserDetailsByUserIds(Set<String> userIds) {
try {
HttpRequestUtils httpRequestUtils = new HttpRequestUtils(this);
final String userDetailsUrl = "https://apps.applozic.com/rest/ws/user/detail";
if (userIds !=null && userIds.size()>0 ) {
List<String> userDetailsList = new ArrayList<>();
String response = "";
int count = 0;
for (String userId : userIds) {
count++;
userDetailsList.add(userId);
if( count% 60==0){
UserDetailListFeed userDetailListFeed = new UserDetailListFeed();
userDetailListFeed.setContactSync(true);
userDetailListFeed.setUserIdList(userDetailsList);
String jsonFromObject = GsonUtils.getJsonFromObject(userDetailListFeed, userDetailListFeed.getClass());
Log.i(TAG,"Sending json:" + jsonFromObject);
response = httpRequestUtils.postData(userDetailsUrl + "?contactSync=true", "application/json", "application/json", jsonFromObject);
userDetailsList = new ArrayList<String>();
if(!TextUtils.isEmpty(response)){
List<UserDetail> userDetails = (List<UserDetail>) GsonUtils.getObjectFromJson(response, new TypeToken<List<UserDetail>>() {}.getType());
for (UserDetail userDetail : userDetails) {
//Here you will get the user details
Log.i("UserDeatil","userId:"+userDetail.getUserId()) ;
Log.i("UserDeatil","display name:"+userDetail.getDisplayName()) ;
Log.i("UserDeatil","image link:"+userDetail.getImageLink()) ;
Log.i("UserDeatil","phone number:"+userDetail.getPhoneNumber()) ;
}
}
}
}
if(!userDetailsList.isEmpty()&& userDetailsList.size()>0) {
UserDetailListFeed userDetailListFeed = new UserDetailListFeed();
userDetailListFeed.setContactSync(true);
userDetailListFeed.setUserIdList(userDetailsList);
String jsonFromObject = GsonUtils.getJsonFromObject(userDetailListFeed, userDetailListFeed.getClass());
response = httpRequestUtils.postData(userDetailsUrl + "?contactSync=true", "application/json", "application/json", jsonFromObject);
Log.i(TAG, "User details response is :" + response);
if (TextUtils.isEmpty(response) || response.contains("<html>")) {
return null;
}
if (!TextUtils.isEmpty(response)) {
List<UserDetail> userDetails = (List<UserDetail>) GsonUtils.getObjectFromJson(response, new TypeToken<List<UserDetail>>() {}.getType());
for (UserDetail userDetail : userDetails) {
//Here you will get the user details
Log.i("UserDeatil","userId:"+userDetail.getUserId()) ;
Log.i("UserDeatil","display name:"+userDetail.getDisplayName()) ;
Log.i("UserDeatil","image link:"+userDetail.getImageLink()) ;
Log.i("UserDeatil","phone number:"+userDetail.getPhoneNumber()) ;
} }
}
return response;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
I did the login using Google Identity Toolkit, I have noticed that the class GitkitUser.UserProfile retrieves the photo url, but is too small. The google documentation do not say anything about photo size.
https://developers.google.com/identity/toolkit/android/reference/com/google/identitytoolkit/GitkitUser.UserProfile.html#getPhotoUrl()
For example with Facebook login, the getPhotoUrl() method returns:
https://scontent.xx.fbcdn.net/hprofile-xap1/v/t1.0-1/p50x50/12651146_10208004779813340_3124516205553866664_n.jpg?oh=efa817d10aaf9d184a767bae81a71071&oe=576850AD
For example with Gmail login, the getPhotoUrl() method returns:
https://lh6.googleusercontent.com/-5XFRyKHh7Os/AAAAAAAAAAI/AAAAAAAABIo/Trf7GjTnFec/s96-c/photo.jpg
Deleting /s96-c (or replace to /s200-c) in the Gmail photo url appears big, but I need a workaround to Facebook photo.
The solution for android was obtain the federatedId and after that call:
http://graph.facebook.com/{federatedId}/picture?type=large
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
client = GitkitClient.newBuilder(this, new GitkitClient.SignInCallbacks() {
#Override
public void onSignIn(IdToken idToken, GitkitUser user) {
DataStorage.getInstance().setLastToken(idToken.getTokenString());
Configuration config = Configuration.fromMetaData(AppInfo.getAppInfo(LoginActivity.this).metaData);
ApiClient apiClient = new ApiClient(config.getApiKey(), AppInfo.getAppInfo(LoginActivity.this), config.getServerWidgetUrl());
final GetAccountInfo.Request request = apiClient.newGetAccountInfoRequest(idToken);
new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
GetAccountInfo.Response accountInfo = request.execute();
JSONArray users = accountInfo.getJsonResponse().optJSONArray("users");
JSONObject user = users == null ? null : users.optJSONObject(0);
String email = user == null ? null : user.optString("email");
if (email != null) {
JSONArray providerUserInfo = user.optJSONArray("providerUserInfo");
if (providerUserInfo != null && providerUserInfo.length() != 0) {
for (int i = 0; i < providerUserInfo.length(); ++i) {
JSONObject userInfo = providerUserInfo.optJSONObject(i);
if (userInfo != null) {
try {
String userInfoString = userInfo.getString("federatedId");
if(userInfoString.contains("facebook.com")) {
int lastSlash = userInfoString.lastIndexOf("/");
if(lastSlash != -1) {
String federatedIdFacebook = userInfoString.substring(lastSlash + 1, userInfoString.length());
Log.i("federatedIdFacebook", federatedIdFacebook);
}
break;
}
} catch (JSONException e) {
Log.e("LoginActivity", e.getMessage());
}
}
}
}
}
return null;
}
}.execute();
}
#Override
public void onSignInFailed() {
Toast.makeText(LoginActivity.this, "Sign in failed", Toast.LENGTH_LONG).show();
}
}).build();
}
You could use the idToken to get the User's identifier at IDP (facebook id).
See users[].providerUserInfo[].federatedId at https://developers.google.com/identity/toolkit/web/reference/relyingparty/getAccountInfo
And then use the facebookId to get the large account picture, with
http://graph.facebook.com/{facebookId}/picture?type=large
i am using Facebook Graph API to get user's feed. But when i get string which is defined "story", it comes in English what i do. Should i do get it different languages ? How/Where i can use "locale" value(fr_FR or tr_TR) while i am doing query ? Here's my code:
EDIT: FacebookFeed is my POJO class.
LoginManager.getInstance().logInWithReadPermissions(FacebookScreen.getMe(), Arrays.asList("user_posts"));
Bundle parameters = new Bundle();
parameters.putString("fields", "created_time,story,message,link,picture");
GraphRequest request = new GraphRequest(AccessToken.getCurrentAccessToken(), "/v2.3/me/feed", parameters, HttpMethod.GET, new Callback() {
#Override
public void onCompleted(GraphResponse response) {
JSONObject object = response.getJSONObject();
for (int i = 0; i < object.optJSONArray("data").length(); i++) {
FacebookFeed feed = new FacebookFeed();
if (object.optJSONArray("data").optJSONObject(i).optString("story") != null) {
feed.setStory(object.optJSONArray("data").optJSONObject(i).optString("story"));
Log.i("log1", "if1");
}
if (object.optJSONArray("data").optJSONObject(i).optString("message") != null) {
feed.setMessage(object.optJSONArray("data").optJSONObject(i).optString("message"));
Log.i("log2", "if2");
}
if (object.optJSONArray("data").optJSONObject(i).optString("created_time") != null) {
feed.setTime(object.optJSONArray("data").optJSONObject(i).optString("created_time"));
Log.i("log3", "if3");
}
if (object.optJSONArray("data").optJSONObject(i).optString("picture") != null) {
String urlString=object.optJSONArray("data").optJSONObject(i).optString("picture");
feed.setPicture(urlString);
Log.i("log4", "if4");
}
if (object.optJSONArray("data").optJSONObject(i).optString("link") != null) {
feed.setLink(object.optJSONArray("data").optJSONObject(i).optString("link"));
Log.i("log5", "if5");
}
feedList.add(feed);
Log.i("LOG", "added to list");
}
}
});
request.executeAsync();
You can try to add
parameters.putString("locale", "fr_FR");
This works at least in the Graph API Explorer:
I am working with Facebook graph api:
I need to get the list of friends who have already AUTHENTICATED MY APPLICATION.
First question:
IS THIS POSSIBLE?
and if yes please guide me where should I start searching for it.
I have already gone through SO for similar question and none suits in my case.
Please help!
Thank you.
Facebook API provides a boolean field that can help you filter the User's friends with your application Installed. You need to Make a request for User's Friends List and set the required fields to include the "installed" boolean. The following code snippet may help you out.
private void requestMyAppFacebookFriendsWithAppInstalled(Session session) {
Request friendsRequest = createRequest(session);
friendsRequest.setCallback(new Request.Callback()
{
#Override
public void onCompleted(Response response)
{
//SetUpList
List<GraphUser> friends = getResults(response);
GraphUser user;
friendsList=new ArrayList<ACT_friendsListPicker.FB_FriendsListStructure>();
boolean installed = false;
if(friends!=null)
{
for(int count=0;count<friends.size();count++)
{
user = friends.get(count);
if(user.getProperty("installed") != null)
{
installed = (Boolean) user.getProperty("installed");
Log.i("frndsPickerAppInstalled? YES ","user: "+user.getInnerJSONObject());
}
}}}});
private Request createRequest(Session session) {
Request request = Request.newGraphPathRequest(session, "me/friends", null);
Set<String> fields = new HashSet<String>();
String[] requiredFields = new String[] { "id", "name", "picture","hometown",
"installed" };
fields.addAll(Arrays.asList(requiredFields));
Bundle parameters = request.getParameters();
parameters.putString("fields", TextUtils.join(",", fields));
request.setParameters(parameters);
return request;
}
private class FB_FriendsListStructure
{
String Name,ID,ImageUrl;
boolean selected;
}
private List<GraphUser> getResults(Response response) throws NullPointerException
{
try{
GraphMultiResult multiResult = response
.getGraphObjectAs(GraphMultiResult.class);
GraphObjectList<GraphObject> data = multiResult.getData();
return data.castToListOf(GraphUser.class);
}
catch(NullPointerException e)
{
return null;
//at times the flow enters this catch block. I could not figure out the reason for this.
}
}
I am creating webDialog for sending friend request on facebook.I am able to create web-dialog and send friend request but I don't know to parse bundle date.Once request is send and if there is no error I am getting the response of facebook in the following manner Bundle[{to[0]=100005695389624, to[1]=100002812207673, request=333965433373671}].I want to parse this data.How can I do this.
I am able to get request from the above data but how can i get the to parameter from it.If any one is having any idea then please let me know.
I tried in the following manner.
final String requestId = values.getString("request"); // This value retrieved properly.
char at[] = values.getString("to").toCharArray(); // returns null
String str[] = values.getStringArray("to"); // returns null
String s = values.getString("to"); // return null
I am creating WebDialog for inviting friends of facebook.In response of that I am getting the values in bundle in following format.
Bundle[{to[0]=10045667789624, to[1]=1353002812207673, request=1234555}]
So I was having issues in parsing data of the bundle.I resolved it in the following manner.
Bundle params = new Bundle();
params.putString("message", "Message from Android App.");
WebDialog requestsDialog = (
new WebDialog.RequestsDialogBuilder(ChatRoom.this,
Session.getActiveSession(),
params))
.setOnCompleteListener(new OnCompleteListener() {
#Override
public void onComplete(Bundle values,FacebookException error) {
if( values != null)
{
final String requestId = values.getString("request");
ArrayList<String> friendsId = new ArrayList<String>();
int i = 0;
String to;
do {
to = values.getString("to[" +i + "]");
if(!TextUtils.isEmpty(to))
{
friendsId.add(to);
}
i++;
} while (to != null);
if (requestId != null) {
Toast.makeText(ChatRoom.this.getApplicationContext(),"Request sent",Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(ChatRoom.this.getApplicationContext(),"Request cancelled",Toast.LENGTH_SHORT).show();
}
}
toggle();
}
})
.build();
requestsDialog.show();
Hope this could help someone.
I don't know whether it will work, but try viewing the to array as just a String.
final String requestId = values.getString("request");
final String to0 = values.getString("to[0]");
final String to1 = values.getString("to[1]");
If you don't know how many of these to strings you have, you could create a simple while loop and continue until it returns null. It's not an elegant solution, but it's the only one I can come up with right now. If you know more about the bundle, you can probably find a better solution.
ArrayList<String> to = new ArrayList<String>();
int i = 0;
while (true) {
String x = values.getString("to["+i+"]");
if (x == null) {
break;
} else {
to.add(x);
i++;
}
}