许可facebook sdk Android [英] Permission facebook sdk Android

查看:90
本文介绍了许可facebook sdk Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Facebook上工作。无法获取 publish_actions 权限。使用以下代码:

Working on Facebook. Unable to get publish_actions permission. Using this code:

session.requestNewPublishPermissions(new
Session.NewPermissionsRequest(this, PERMISSION));

任何解决方案...

推荐答案

Facebook sdk只返回读权限,但不返回写权限。您可以使用/ me端点获取所有权限。

Facebook sdk only returns read-permission, but not the write permissions. You can user the "/me" endpoint to get all the permissions.

    final Bundle permBundle = new Bundle();
    permBundle.putCharSequence("permission", "publish_actions");
    GraphRequest request = new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            "/me/permissions", permBundle, HttpMethod.GET,
            new GraphRequest.Callback() {
                @Override
                public void onCompleted(GraphResponse graphResponse) {
                    Log.d(TAG, "response2: " + graphResponse.getJSONObject());
                    try {
                        JSONArray permList = (JSONArray) graphResponse.getJSONObject().get("data");
                        if(permList.length() == 0){
                            // no data for perms, hence asking permission
                            askForFBPublishPerm();
                        }else{
                            JSONObject permData = (JSONObject) permList.get(0);
                            String permVal = (String) permData.get("status");
                            if(permVal.equals("granted")){
                                postToFB();
                            }else{
                                askForFBPublishPerm();
                            }
                        }
                    } catch (JSONException e) {
                        Log.d(TAG, "exception while parsing fb check perm data" + e.toString());
                    }

                }
            }
    );
    request.executeAsync();

这篇关于许可facebook sdk Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆