[英]how to access facebook friends list using social auth in android?
I am using social auth library for facebook integration. 我正在使用社交身份验证库进行Facebook集成。 I am able to share/post text or images but i want to access my friend list. 我可以共享/发布文本或图像,但我想访问我的朋友列表。
Is it possible to access friend list via social auth in android? 是否可以通过Android中的社交身份验证访问朋友列表?
Thanks in advance... 提前致谢...
I am using socialauth to get a list of friends in Facebook. 我正在使用socialauth获取Facebook中的朋友列表。 They have more up to date information on their github page wiki . 他们在github页面wiki上有更多最新信息。 The code below is my adaptation of the examples in the wiki. 下面的代码是我对Wiki中的示例的改编。 I am getting Name, profile image and Facebook id. 我正在获取姓名,个人资料图片和Facebook ID。
in my Fragment: 在我的片段中:
public class Friends extends SherlockFragment {
private static SocialAuthAdapter facebookAdapter;
I set up the adapter 我设置了适配器
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
facebookAdapter = new SocialAuthAdapter(new FacebookListener());
later in onCreateView I authorize the user 稍后在onCreateView中,我授权用户
facebookAdapter.authorize(getSherlockActivity(), Provider.FACEBOOK);
Now I implement the first Listener (did they authorize) 现在,我实现第一个侦听器(他们授权了)
private final class FacebookListener implements DialogListener
{
public void onComplete(Bundle values) {
Log.d("SocialAuth","Successful");
facebookAdapter.getUserProfileAsync(new FacebookProfileDataListener());
Toast.makeText(getSherlockActivity(),"Connection Successful",Toast.LENGTH_LONG).show();
}
@Override
public void onError(SocialAuthError error) {
Log.d("Custom-UI" , "Error");
}
public void onCancel() {
Log.d("Custom-UI" , "Cancelled");
}
@Override
public void onBack() {
// TODO Auto-generated method stub
}
}
Now I get the profile 现在我得到了个人资料
public final class FacebookProfileDataListener implements org.brickred.socialauth.android.SocialAuthListener<Profile> {
@Override
public void onError(SocialAuthError arg0) {
// TODO Auto-generated method stub
}
@Override
public void onExecute(String arg0, Profile profile) {
if (profile.getProviderId().equalsIgnoreCase(Provider.FACEBOOK.name())) {
//store some of the profile information here
}
facebookAdapter.getContactListAsync(new FacebookContactDataListener());
}
}
Now the Contact List 现在联系人列表
public final class FacebookContactDataListener implements SocialAuthListener<List<Contact>> {
@Override
public void onError(SocialAuthError arg0) {
// TODO Auto-generated method stub
}
@Override
public void onExecute(String arg0, List<Contact> t) {
List<Contact> contactList = t;
JSONArray listOfIds = new JSONArray();
for (Contact c: contactList) {
listOfIds.put(c.getId());
}
AppDataManager manager = AppDataManager.getInstance(getSherlockActivity());
manager.setFacebookFriendsIds(listOfIds);
manager.setFacebookFriends(contactList);
}
}
At this point I have a List that I can work with. 此时,我有一个可以使用的列表。
https://developers.facebook.com/tools/ https://developers.facebook.com/tools/
Use Graph Api Search . 使用图形Api搜索。
https://graph.facebook.com/YOUR_ID?fields=friends , will show you whole list of friends . https://graph.facebook.com/YOUR_ID?fields=friends ,将向您显示整个朋友列表。
https://graph.facebook.com/YOUR_ID?fields=friendlists , will show you only 25 friends . https://graph.facebook.com/YOUR_ID?fields=friendlists ,只会显示25个朋友。
This is the correct answer: add this to your oauth_consumer.properties file, under the line containing graph.facebook.com.consumer_secret
: 这是正确的答案:在包含graph.facebook.com.consumer_secret
的行下,将其添加到oauth_consumer.properties文件:
graph.facebook.com.custom_permissions = user_friends
or read_friendlists
depending on what permissions you truly need. 或read_friendlists
具体取决于您真正需要的权限。
Check https://developers.facebook.com/docs/facebook-login/permissions/v2.0 for more info about permissions. 检查https://developers.facebook.com/docs/facebook-login/permissions/v2.0了解有关权限的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.