0

私のアプリに統合されているFacebookウィジェットを介してすでにログインしているユーザーのFacebookの友達を取得したいと思います。

友達リストを取得するアクティビティを作成しましたが、うまくいきません。(ログインしたユーザーのFacebook IDもString 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

        }
    }

}

LogCat:

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)

ありがとう

4

0 に答える 0