@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.activity_main, container, false);
LoginButton authButton = (LoginButton) view
.findViewById(R.id.authButton);
authButton.setFragment(this);
authButton.setReadPermissions(Arrays.asList("user_likes",
"friends_birthday", "friends_about_me"));
return view;
// return super.onCreateView(inflater, container, savedInstanceState);
}
这就是我试图获取生日的方式
private void onSessionStateChange(Session session, SessionState state,
Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
Request.executeMyFriendsRequestAsync(session,
new Request.GraphUserListCallback() {
@Override
public void onCompleted(List<GraphUser> users,
Response response) {
// TODO Auto-generated method stub
// Log.i("Response JSON", response.toString());
names = new String[users.size()];
id = new String[users.size()];
for (int i = 0; i < users.size(); i++) {
names[i] = users.get(i).getBirthday();
//id[i] = users.get(i).ge();
Log.i("Birthday chakk te bai ", "Birthday"
+ names[i]);
}
}
});
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
请查看我为什么要打零。当我为朋友的名字测试它时,keyhash的每件事情都很好。
应用仅适用于沙盒模式。
答案 0 :(得分:0)
试试这个 -
您的回调,您将获得朋友和生日信息(如果经过身份验证):
Session.StatusCallback statusCallback = new Session.StatusCallback()
{
// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception)
{
if (session.isOpened())
{
getFriendDetails();
}
}
};
然后,打开会话并设置权限:
Session session = new Session(this);
session.openForRead(new Session.OpenRequest(this)
.setCallback(statusCallback)
.setPermissions(Arrays.asList("friends_birthday")));
作为最后一步,获取朋友的生日和其他详细信息:
private void getFriendDetails()
{
Request myFriendsRequest = Request.newMyFriendsRequest(Session.getActiveSession(),
new Request.GraphUserListCallback()
{
@Override
public void onCompleted(List<GraphUser> users, Response response)
{
if (response.getError() == null)
{
// Print response
}
}
});
Bundle requestParams = myFriendsRequest.getParameters();
requestParams.putString("fields", "name,birthday");
myFriendsRequest.setParameters(requestParams);
myFriendsRequest.executeAsync();
}