0

FacebookのグラフAPIを使用して、PHPによるFAN-PAGEのステータスを更新したいと思います。グーグルは言う:動作しません。

ここで、自分のユーザーステータスをPHPで更新したいと思います。私の主な問題は、ブラウザーを使用せず、面白いPHPの回避策を使用せずに、自分のユーザーをグラフAPI(PHPを使用)にログインする方法です。

4

3 に答える 3

1

私の主な問題は、ブラウザーを使用せず、面白い php 回避策を使用せずに、自分のユーザーをグラフ API (php を使用) にログインする方法です。

. _ _ _offline_access

許可を取得するoffline_access方法とそれ以降の使用方法は、この回答で説明されています。

編集:
コメントを読んでください!ありがとう@zerkms!

于 2011-02-01T10:01:50.637 に答える
1

どちらの場合も、publish_stream許可を取得する必要がありますhttp://developers.facebook.com/docs/authentication/permissions

これはFB.login()で実行できます

詳細: http://developers.facebook.com/docs/authentication

その後、グラフ API の投稿でステータスを更新できます: http://developers.facebook.com/docs/reference/api/post

于 2011-02-01T09:37:18.590 に答える
1

Facebook プロファイルまたはページのフィードを更新するには、Facebook アプリケーション ( client_idclient_secret )、profile_id、およびaccess_token (publish_stream、manage_pages、offline_access パーミッション) が必要です。

そうしないと、アクセス トークンの有効期限が切れてしまうため、offline_access が必要です。既に publish_stream が指定されている場合、offline_access は必要ないことを読んだ場合は、必ずしも必要ではないことを意味しています。

投稿を公開するのは簡単です:

$data = array(
    'access_token' => $access_token,
    'message' => 'status message',
    );
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/{$profile_id}/feed");

profile_idaccess_tokenを取得する方法は、私の app post pandaを使用するか、独自のスクリプトを作成することができます。ここに含めます:

# arvin castro
# http://codecri.me/
# January 16, 2011

$client_id     = ''; # application id
$client_secret = ''; # application secret
$callbackURL   = 'http://'; # the URL of this script
$extendedPermissions = 'publish_stream,manage_pages,offline_access';

session_name('facebookoauth');
session_start();

if(isset($_GET['logout']) and $_SESSION['loggedin']) {
    $_SESSION = array();
    session_destroy();
}

if(isset($_GET['signin'])) {

    # STEP 1: Redirect user to Facebook, to grant permission for our application
    $url = 'https://graph.facebook.com/oauth/authorize?' . xhttp::toQueryString(array(
        'client_id'    => $client_id,
        'redirect_uri' => $callbackURL,
        'scope'        => $extendedPermissions,
    ));
    header("Location: $url", 303);
    die();
}

if(isset($_GET['code'])) {

    # STEP 2: Exchange the code that we have for an access token
    $data = array();
    $data['get'] = array(
        'client_id'     => $client_id,
        'client_secret' => $client_secret,
        'code'      => $_GET['code'],
        'redirect_uri'  => $callbackURL,
        );

    $response = xhttp::fetch('https://graph.facebook.com/oauth/access_token', $data);

    if($response['successful']) {

        $var = xhttp::toQueryArray($response['body']);
        $_SESSION['access_token'] = $var['access_token'];
        $_SESSION['loggedin']     = true;

    } else {
        print_r($response['body']);
    }
}

if($_SESSION['loggedin']) {
    // Get Profile ID
    $data = array();
    $data['get'] = array(
            'access_token'  => $_SESSION['access_token'],
            'fields' => 'id,name,accounts',
            );  
    $response = xhttp::fetch('https://graph.facebook.com/me', $data);
    echo '<pre>';
    print_r(json_decode($response['body'], true));
    echo '</pre>';

} else {
    echo '<a href="?signin">Sign in with Facebook</a>';
}

?>

cURL ラッパー クラスxhttpを使用しています。

于 2011-02-01T15:04:26.413 に答える