Java 权限错误-尝试使用android facebook sdk获取好友

Java 权限错误-尝试使用android facebook sdk获取好友,java,android,facebook,facebook-graph-api,Java,Android,Facebook,Facebook Graph Api,我正试图在我的android应用程序中添加一项功能,允许用户与标记为签入的其他人一起签入。 我的checkins方法工作正常,可以通过添加用户ID作为参数来标记某个用户,请参见下面的代码 public void postLocationTagged(String msg, String tags, String placeID, Double lat, Double lon) { Log.d("Tests", "Testing graph API location post");

我正试图在我的android应用程序中添加一项功能,允许用户与标记为签入的其他人一起签入。 我的checkins方法工作正常,可以通过添加用户ID作为参数来标记某个用户,请参见下面的代码

public void postLocationTagged(String msg, String tags, String placeID, Double lat, Double lon) {
    Log.d("Tests", "Testing graph API location post");
    String access_token = sharedPrefs.getString("access_token", "x");
     try {
         if (isSession()) {
            String response = mFacebook.request("me");
            Bundle parameters = new Bundle();
            parameters.putString("access_token", access_token);
            parameters.putString("place", placeID);
            parameters.putString("Message",msg);
            JSONObject coordinates = new JSONObject();
            coordinates.put("latitude", lat);
            coordinates.put("longitude", lon);
            parameters.putString("coordinates",coordinates.toString());
            parameters.putString("tags", tags);
            response = mFacebook.request("me/checkins", parameters, "POST");
            Toast display = Toast.makeText(this, "Checkin has been posted to Facebook.", Toast.LENGTH_SHORT);
            display.show();
            Log.d("Tests", "got response: " + response);
            if (response == null || response.equals("") || 
                    response.equals("false")) {
               Log.v("Error", "Blank response");
            }
        } else {
         // no logged in, so relogin
         Log.d(TAG, "sessionNOTValid, relogin");
         mFacebook.authorize(this, PERMS, new LoginDialogListener());
        }
     } catch(Exception e) {
         e.printStackTrace();
     }
}
这很好,我已经发布了,以防对其他人有帮助!,我遇到的问题是,我正在尝试创建一个用户朋友列表,以便他们可以选择要标记的朋友。我有下面的方法getFriends see,我将使用该方法生成一个AlertDialog,用户可以从中选择,然后再从中为我提供在上述postLocationTagged方法中使用的id

public void getFriends(CharSequence[] charFriendsNames,CharSequence[] charFriendsID, ProgressBar progbar) {
    pb = progbar;
    try {
        if (isSession()) {
            String access_token = sharedPrefs.getString("access_token", "x");
            friends = charFriendsNames;
            friendsID = charFriendsID;
           Log.d(TAG, "Getting Friends!");
           String response = mFacebook.request("me");
           Bundle parameters = new Bundle();
           parameters.putString("access_token", access_token);
           response = mFacebook.request("me/friends", parameters, "POST");

           Log.d("Tests", "got response: " + response);
           if (response == null || response.equals("") || 
                   response.equals("false")) {
              Log.v("Error", "Blank response");
           }

        } else {
        // no logged in, so relogin
        Log.d(TAG, "sessionNOTValid, relogin");
        mFacebook.authorize(this, PERMS, new LoginDialogListener());
        }
    } catch(Exception e) {
        e.printStackTrace();
    }
}
当我查看日志中的响应时,它显示:

获取响应:{错误:{类型:OAutheException,消息:200权限错误}


我已经浏览了graphAPI文档并搜索了类似的问题,但没有结果!我不确定我是否需要为应用程序请求额外的权限,或者这是你不允许做的事情!非常感谢您的帮助/建议。

您可能需要以下权限:

用户签入 朋友登记 阅读你的朋友名单 管理你的朋友名单 发布签入
检查API文档中的相关内容。在此之前,请确保哪一行导致此权限错误,并尝试修复它。

解决方案是在向Facebook graph API发出请求时实现RequestListener。我有一个新的getFriends方法,如下所示,它使用AsyncGacebookRunner请求数据

public void getFriends(CharSequence[] charFriendsNames,String[] sFriendsID, ProgressBar progbar) {
    try{
        //Pass arrays to store data
        friends = charFriendsNames;
        friendsID = sFriendsID;
        pb = progbar;
        Log.d(TAG, "Getting Friends!");
        //Create Request with Friends Request Listener
        mAsyncRunner.request("me/friends", new FriendsRequestListener());
    } catch (Exception e) {
        Log.d(TAG, "Exception: " + e.getMessage());
    }
}
AsyncFacebookRunner使用实现RequestListener类的自定义FriendsRequestListener发出请求,请参见下文

private class FriendsRequestListener implements RequestListener {
    String friendData;

    //Method runs when request is complete
    public void onComplete(String response, Object state) {
        Log.d(TAG, "FriendListRequestONComplete");
        //Create a copy of the response so i can be read in the run() method.
        friendData = response; 

        //Create method to run on UI thread
        FBConnectActivity.this.runOnUiThread(new Runnable() {
            public void run() {
                try {
                    //Parse JSON Data
                    JSONObject json;
                    json = Util.parseJson(friendData);

                    //Get the JSONArry from our response JSONObject
                    JSONArray friendArray = json.getJSONArray("data");

                    //Loop through our JSONArray
                    int friendCount = 0;
                    String fId, fNm;
                    JSONObject friend;
                    for (int i = 0;i<friendArray.length();i++){
                        //Get a JSONObject from the JSONArray
                        friend = friendArray.getJSONObject(i);
                        //Extract the strings from the JSONObject
                        fId = friend.getString("id");
                        fNm = friend.getString("name");
                        //Set the values to our arrays
                        friendsID[friendCount] = fId;
                        friends[friendCount] = fNm;
                        friendCount ++;
                        Log.d("TEST", "Friend Added: " + fNm);
                    }

                    //Remove Progress Bar
                    pb.setVisibility(ProgressBar.GONE);

                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (FacebookError e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
    }

您可以在自己的项目中随意使用这些代码,也可以提出任何问题。

您可以将静态最终字符串[]权限=新字符串[]{publish\u stream,status\u update,xxxx};xxx是premissions

谢谢Ahmet,我刚刚发现,这不是权限问题,而是我向graph API提交请求的方式。我要吃点晚餐,然后发表评论并发布我的解决方案。无论如何,谢谢你的回答-查看“阅读/管理好友权限”列表给了我一个在我的应用程序中实现的好主意!这看起来像奥维基尔。刚刚调试过类似的问题,看起来更像是你在做一个POST请求,而你本应该做一个GET。是否可以使用搜索文本框按姓名筛选朋友??