-1

facebook.com から友達リクエストを受信しようとしましたが、例外が発生しました

W/System.err(1139): com.facebook.android.FacebookError: OAuth アクセス トークンが無効です。W/System.err(1139): com.facebook.android.Util.parseJson(Util.java:279) で W/System.err(1139): test.project.facebook.AutFacebookActivity$1$2.onComplete(AutFacebookActivity. java:147) W/System.err(1139): at com.facebook.android.AsyncFacebookRunner$2.run(AsyncFacebookRunner.java:254)

私のJavaコード:

private void authorize(){
    intent = new Intent(AutFacebookActivity.this,FaceListView.class);
        fb.authorize(this,new DialogListener(){

            @Override
            public void onComplete(Bundle values){
                Toast.makeText(AutFacebookActivity.this,"Вы вошли",Toast.LENGTH_LONG).show();
                asyncRanFace.request("me/friends",new RequestListener(){
            public void onComplete(String response, Object state) {
                try{
                    JSONObject json = Util.parseJson(response);
                    JSONArray friendsArray =  json.getJSONArray("data");

                    //friendsList = new ArrayList<HashMap>();

                    String fId,fNm;
                    JSONObject friend;
                    for(int i =0 ; i<friendsArray.length(); i++){
                        friend = friendsArray.getJSONObject(i);
                        fId = friend.getString("id");
                        fNm= friend.getString("name");
                        myFriendsMap.put(fId, fNm);


                    }
                    intent.putExtra("map1",myFriendsMap);

                }catch(JSONException e){
                    e.printStackTrace();
                    }
                catch(FacebookError e){
                    e.printStackTrace();
                }
            }
            @Override
            public void onFacebookError(FacebookError e, Object state) {
                // TODO Auto-generated method stub

            }
            @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

            }


            });
                asyncRanFace.request("me/friendrequests?access_token=read_requests",new RequestListener(){

                            public void onComplete(String res, Object state) {
                                try{
                                    JSONObject jsonRequest = Util.parseJson(res);
                                    JSONArray friendsRequestArray =  jsonRequest.getJSONArray("data");
                                    JSONObject friendRequest;
                                    String fRId,fRNm;
                                    for(int i =0 ; i<friendsRequestArray.length(); i++){
                                        friendRequest= friendsRequestArray.getJSONObject(i);
                                        fRId = friendRequest.getString("id");
                                        fRNm= friendRequest.getString("name");
                                        myRequestFriendsMap.put(fRId, fRNm);
                                        intent.putExtra("map2",myRequestFriendsMap);
                                        startActivity(intent);
                                    }

                        }catch(JSONException e){
                            e.printStackTrace();
                        }
                    catch(FacebookError e){
                        e.printStackTrace();
                    }

        }
                            @Override
                            public void onFacebookError(FacebookError e, Object state) {
                                // TODO Auto-generated method stub

                            }
                            @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) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onError(DialogError e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onCancel() {
                // TODO Auto-generated method stub
                Toast.makeText(AutFacebookActivity.this, "Вы вышли", Toast.LENGTH_LONG).show();

            }




        });


}
4

1 に答える 1

0

これは Facebook 部分のコード全体ですか? まず、Facebook を Autorize し、AccessToken を取得する必要があります (必要に応じて保存して再利用します)。

それからちょうど:

mAsyncRunner.request("me/friends", new FriendsRequestListener());

private class FriendsRequestListener implements RequestListener 
{           
            @Override
            public void onComplete(String response, Object state) 
            {
                    try 
                    {
                            JSONObject json = Util.parseJson(response);
                            JSONArray friends = json.getJSONArray("data");                               
                    } 
                    catch (JSONException e) 
                    {
                            Log.e("OnComplete","JSONException");
                    }
                    catch (FacebookError e) 
                    {
                            Log.e("OnComplete","FacebookError");
                    }
            }
            @Override
            public void onIOException(IOException e, Object state)
            {
                    Log.e("FriendsRequest","onIOException");
            }
            @Override
            public void onFileNotFoundException(FileNotFoundException e,Object state)
            {
                    Log.e("FriendsRequest","onFileNotFoundException");
            }
            @Override
            public void onMalformedURLException(MalformedURLException e,Object state)
            {
                    Log.e("FriendsRequest","onMalformedURLException");
            }
            @Override
            public void onFacebookError(FacebookError e, Object state)
            {
                    Log.e("FriendsRequest","onFacebookError");
            }
    }
于 2012-05-19T11:56:37.037 に答える