1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AndroidのFacebookログイン時に投稿権限をリクエストすると落ちる

Posted at

Androidいじいじしててはまったところメモ。

現象

AndroidでFacebookSDKを使って以下のようなコードを書くとエラーで落ちる。

Session.openActiveSession(activity, true, Arrays.asList("publish_actions"), new Session.StatusCallback() {
    public void call(final Session session, SessionState state, Exception exception) {
    }
}

エラーメッセージ

com.facebook.FacebookException: Cannot pass a publish or manage permission (publish_actions) to a request for read authorization

対応方法

エラーメッセージやこちらの回答にもあるが基本的な権限がないとpublish_actions権限を取得できない。
こちらの回答にあるように、ログイン(基本的な権限の取得)とpublish_actions権限の取得を分ける必要がある。
FacebookSDkのサンプルのHelloFacebookSampleやscrumptiousが同じようなやり方をしている。

Session.openActiveSession(activity, true, new Session.StatusCallback() {
    public void call(final Session session, SessionState state, Exception exception) {
        if (session.isOpend()) {
            Session.NewPermissionsRequest req = new Session.NewPermissionsRequest(activity, Arrays.asList("publish_actions"));
            session.requestNewPublishPermissions(req);
        }
    }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?