PHPでfacebook投稿時に公開範囲を指定する方法

[参考記事] facebook APIを使用する時にfacebook Appsでアプリを登録するまでの流れ
[参考記事] PHPでのfacebookアプリの認証処理(APIを使うユーザー認証)
[参考記事] PHPでfacebookのフィード(ウォール)に投稿する方法
[参考記事] PHPで複数の画像をfacebookに投稿する方法

投稿時に公開範囲を指定するには privacyパラメータを使います。

try {
  $me = $facebook->api('/me');
  $result = $facebook->api("/me/feed", "post", array(
    "message" => 'このメッセージが投稿されます。',
    "privacy" => array(
      "value" => "EVERYONE",
    ),
  ));
} catch (FacebookApiException $e) {
  throw new Exception($e->getMessage());
}
EVERYONE 公開
FRIENDS_OF_FRIENDS 友達の友達
ALL_FRIENDS 友達
SELF 自分のみ
CUSTOM カスタム

アプリの設定画面で設定した公開範囲(デフォルトのアクティビティのプライバシー)


↑これがアプリの認証画面の初期値になります。


公開範囲はユーザーのアプリ管理画面より変更できます。
アプリセンター

  ↓
下のほうのアプリ(上にあるアプリではない)

  ↓
アプリの設定

  ↓
アプリと投稿の共有範囲



ユーザーが設定している値より上位の設定にはできないようです。

https://developers.facebook.com/docs/reference/api/privacy-parameter/
Note: The privacy parameter only applies for posts to the user's own timeline and is ultimately governed by the privacy ceiling a user has configured for an app. It does not apply to posts made by an app on behalf of a user to another user's timelines or to Pages, events, or groups. In those cases, such posts are viewable by anyone who can see the timeline or content in the group or event.
公開範囲を指定できるのはユーザー自身のタイムラインだけです。

Privacy Policy: any non-default privacy setting must be intentionally chosen by the user. You may not set a custom privacy setting unless the user has proactively specified that they want this non-default setting. Note that the visibility of the post will be determined by the more restrictive of the user's privacy setting as well as the post's privacy field.
デフォルト以外の値が使われる場合は、ユーザ自身によって意図的に選ばれなければいけない。

関連記事

スポンサーリンク

特定のスタイルを指定すると省略した終了タグが正しい位置に補われない

ホームページ製作・web系アプリ系の製作案件募集中です。

上に戻る