我遇到了一些问题。这是从我的FB配置文件中获取数据的主要活动。在执行此操作后,将启动另一个活动,并且listview和我的fb朋友列表之间存在联接。当我试图获得他们的生日日期时,活动仅选择一个生日。你可以说"老兄,生日并不总是公开的#34;没错,但是如果我有一个朋友,我可以访问他/她的所有数据,看起来很奇怪,只有600多个朋友中的一个人有公开生日。所以我开始认为问题可能是权限问题。你有什么建议?
public class MainActivity extends FragmentActivity {
SharedPreferences sp;
AccessToken token;
private Button connect;
private String id, name, surname, date, access_token, expires;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
connect=(Button)findViewById(R.id.authButton);
connect.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
openFacebook();
}
});
sp=getPreferences(MODE_PRIVATE);
access_token=sp.getString("access_token", null);
expires=sp.getString("access_expires",null);
if (access_token!=null && expires!=null)
{
token = AccessToken.createFromExistingAccessToken(access_token,null, null, AccessTokenSource.TEST_USER, null);
if (token!=null)
{
connect.setVisibility(View.INVISIBLE);
Session.openActiveSessionWithAccessToken(this,token,new Session.StatusCallback()
{
// callback when session changes state
@Override
public void call(final Session session, SessionState state, Exception exception)
{
if (session.isOpened())
doRequest(session);
}
});
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
private void openFacebook()
{
Session.openActiveSession(this, true, new Session.StatusCallback()
{
// callback when session changes state
@Override
public void call(final Session session, SessionState state, Exception exception)
{
if (session.isOpened())
{
Editor editor = sp.edit();
editor.putString("access_token",session.getAccessToken());
editor.putString("access_expires",session.getExpirationDate().toString());
editor.commit();
doRequest(session);
}
}
});
}
public void doRequest(Session session)
{
Request request = Request.newMeRequest(session, new GraphUserCallback()
{
public void onCompleted(GraphUser user, Response response)
{
if (user != null)
{
Intent myIntent = new Intent(MainActivity.this, LoggedActivity.class);
/*user stuff saved in intent*/
startActivity(myIntent);
}
}
});
Request.executeBatchAsync(request);
}
}