10

自分のアプリケーションウォールにスクリプト付きのテキストを投稿したいのですが、自動的に行われる必要があるため、最初にログインする必要はありません。どうすればそれができますか?私はすでに試しました:

$fb = new Facebook(array(
    'appId'  => 'appid',
    'secret' => 'appsecret',
    'cookie' => true
));


if ($fb->getSession()) {
    // Post
} else {
    // Logger
    // Every time I get in here :(
}

スクリプトを使用して自分のアプリウォールに投稿するためのアクセス権を取得するには、何をする必要がありますか?

4

2 に答える 2

13

独自のアプリケーションウォールに投稿する場合、必要なのはアプリケーションアクセストークンだけです。ログインせずにユーザーウォールに公開する場合は、このユーザーのロングライブアクセストークンも必要です。オフラインアクセス許可。

アプリケーションウォールに公開するには:

1-このリンクをカールして、アプリケーションアクセストークンを取得します。

https://graph.facebook.com/oauth/access_token?client_id = YOUR_APP_ID&client_secret = YOUR_APP_SECRET&grant_type = client_credentials

2-セッションをチェックせずにウォールに公開する

例 :

<?php
require_once 'facebook.php'

//Function to Get Access Token
function get_app_token($appid, $appsecret)
{
$args = array(
'grant_type' => 'client_credentials',
'client_id' => $appid,
'client_secret' => $appsecret
);

$ch = curl_init();
$url = 'https://graph.facebook.com/oauth/access_token';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);

return json_encode($data);
}

// Create FB Object Instance
$facebook = new Facebook(array(
    'appId'  => $appid,
    'secret' => $appsecret,
    'cookie' => false,
    ));


//Get App Token
$token = get_app_token($appid, $appsecret);

//Try to Publish on wall or catch the Facebook exception
try {
$attachment = array('message' => '',
            'access_token' => $token,
                    'name' => 'Attachment Name',
                    'caption' => 'Attachment Caption',
                    'link' => 'http://apps.facebook.com/xxxxxx/',
                    'description' => 'Description .....',
                    'picture' => 'http://www.google.com/logo.jpg',
                    'actions' => array(array('name' => 'Action Text', 
                                      'link' => 'http://apps.facebook.com/xxxxxx/'))
                    );

$result = $facebook->api('/'.$appid.'/feed/', 'post', $attachment);
}

//If the post is not published, print error details
catch (FacebookApiException $e) {
echo '<pre>';
print_r($e);
echo '</pre>';
}

詳細については、このページのAPP LOGIN部分を確認してください: http: //developers.facebook.com/docs/authentication/

于 2011-03-05T18:24:25.263 に答える
3

ポイントがないため、これをコメントとして残すことはできませんが、同様の問題がある場合は、McSharksの回答が機能しない場合は、エンコード引用符としてjson_encodeを削除すると、機能するはずです。

于 2012-01-31T10:30:53.803 に答える