-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,获取 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 回答