Android - 请求发布权限facebook

时间:2016-02-14 12:10:00

标签: android facebook facebook-graph-api

当我尝试授予共享权限(publish_actions)时 它给了我我不能使用Share Dialog或Feed Dialog

发布活动的注释

enter image description here

  

我的应用不使用Facebook Feed对话框或Facebook Share   用于发布内容的对话框

所以它应该如何???

我的代码

 public void publishStory() {

// return list of granted permissions 
        Set<String> permissions = AccessToken.getCurrentAccessToken().getPermissions();


        final List<String> PUBLISH_PERMISSIONS = Arrays.asList("publish_actions");
        // check if publish permission granted or not 
        if (!isSubsetOf(PUBLISH_PERMISSIONS, permissions)) {
            Log.d("FB TAG", "facebook publish permission login");
            pendingPublishReauthorization = true;
            LoginManager.getInstance().logInWithPublishPermissions(this, PUBLISH_PERMISSIONS);

        }
        String AppURL = "https://play.google.com/store/apps/details?id=" + getApplicationContext().getPackageName();

        ShareLinkContent content = new ShareLinkContent.Builder()
                .setContentUrl(Uri.parse(AppURL))
                .setContentTitle("")
                        .build();

        ShareApi.share(content, new FacebookCallback<Sharer.Result>() {

            @Override
            public void onSuccess(Sharer.Result result) {
                Log.d("FBTAG", "Facebook post id is " + result.getPostId());
            }

            @Override
            public void onCancel() {
                // TODO Auto-generated method stub
                Log.d("FBTAG", "Facebook share cancelled");
            }

            @Override
            public void onError(FacebookException error) {
                // TODO Auto-generated method stub
                Log.d("FBTAG", "Facebook error during sharing: " + error.getMessage());

            }
        });
    }

    private boolean isSubsetOf(List<String> publish_permissions, Set<String> permissions) {
        if (Arrays.asList(permissions).contains(publish_permissions))
            return true;

        return false;
    }

这个好的发布到Facebook没有任何通知

任何人都可以建议我怎么做

1 个答案:

答案 0 :(得分:1)

这会奏效。并且请检查您的应用是否在您注册的开发者帐户上有一个绿色圆圈。 from fb developer docs

这将简单地在app上启动facebook sharedialog。它会要求你登录。如果他们没有登录。

 CallbackManager callbackManager;
    ShareDialog shareDialog;

     @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            FacebookSdk.sdkInitialize(getApplicationContext());


            callbackManager = CallbackManager.Factory.create();
            shareDialog = new ShareDialog(this);
     findViewById(R.id.iv_share_fb).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                    shareonFacebook();

                }
            });


    }

      private void shareonFacebook() {
            if (ShareDialog.canShow(ShareLinkContent.class)) {
                ShareLinkContent linkContent = new ShareLinkContent.Builder()
                        .setContentTitle("Shared from stackoverflow")
                        .setContentDescription(
                                "#GoodTimes" + "\n" + "download the TimeWorth app from playstore.")
                        .setContentUrl(Uri.parse(urlToShare))
                        .build();

                shareDialog.show(linkContent);
            } else {
    //this will launch a facebook webpage on browser
                try {
                    String sharerUrl = "http://www.facebook.com/sharer/sharer.php?u=" + urlEncode(urlToShare) + "&t=" + urlEncode((sharemsg1));
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(sharerUrl));
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                } catch (ActivityNotFoundException e) {

                }
            }

        }


        @Override
        protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            callbackManager.onActivityResult(requestCode, resultCode, data);
        }

明显的变化。

    <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">

            <activity
                android:name="com.facebook.FacebookActivity"
                android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
                android:label="@string/app_name"
                android:theme="@android:style/Theme.Translucent.NoTitleBar" /
   <activity
            android:name=".Activity.MainActivity"/>

  ...other activities.    
      <meta-data
                android:name="com.facebook.sdk.ApplicationId"
                android:value="@string/facebook_app_id" />
    </application>