我想为已经通过与我的应用程序集成的 Facebook 小部件登录的用户获取 Facebook 朋友。
我创建了一个检索朋友列表的活动,但它对我不起作用。String id
(我在变量中也有登录用户的 Facebook ID )。
public class FreindsActivity extends Activity {
Facebook mFacebook;
String name,password,email,id,phone,emailOwner;
AsyncFacebookRunner mAsyncRunner;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile_page);
Intent intent = getIntent();
name = intent.getExtras().getString("name");
password = intent.getExtras().getString("password");
email = intent.getExtras().getString("email");
id = intent.getExtras().getString("id");
phone = intent.getExtras().getString("phone");
emailOwner=intent.getExtras().getString("emailOwner");
mFacebook=new Facebook(id);
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
mAsyncRunner.request("me/friends", new FriendsRequestListener());
//Bundle params = new Bundle();
// params.putString("fields", "name,id");
}
public class FriendsRequestListener implements com.facebook.android.AsyncFacebookRunner.RequestListener
{
/**
* Called when the request to get friends has been completed.
* Retrieve and parse and display the JSON stream.
*/
public void onComplete(final String response)
{
try
{
// process the response here: executed in background thread
JSONObject json = Util.parseJson(response);
JSONArray friendsData = json.getJSONArray("data");
String ids[]=new String[friendsData.length()] , names[] = new String[friendsData.length()];
for(int i = 0; i < friendsData .length(); i++){
ids[i] = friendsData .getJSONObject(i).getString("id");
names[i] = friendsData .getJSONObject(i).getString("name");
}
}
catch (JSONException e)
{
}
}
@Override
public void onComplete(String response, Object state) {
// TODO Auto-generated method stub
try
{
JSONObject json = Util.parseJson(response);
JSONArray friendsData = json.getJSONArray("data");
String ids[]=new String[friendsData.length()] , names[] = new String[friendsData.length()];
for(int i = 0; i < friendsData .length(); i++){
ids[i] = friendsData .getJSONObject(i).getString("id");
names[i] = friendsData .getJSONObject(i).getString("name");
}
}
catch (JSONException e){
}
}
@Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
// TODO Auto-generated method stub
}
@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
}
}
日志猫:
03-13 17:24:33.396: E/AndroidRuntime(846): FATAL EXCEPTION: Thread-107
03-13 17:24:33.396: E/AndroidRuntime(846): com.facebook.android.FacebookError: An active access token must be used to query information about the current user.
03-13 17:24:33.396: E/AndroidRuntime(846): at com.facebook.android.Util.parseJson(Util.java:272)
03-13 17:24:33.396: E/AndroidRuntime(846): at com.example.salebook.FreindsActivity$FriendsRequestListener.onComplete(FreindsActivity.java:87)
03-13 17:24:33.396: E/AndroidRuntime(846): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:276)
谢谢