php – Facebook API:如何发布到自己的应用程序墙,没有登录

我想发布到我自己的应用程序墙上一个脚本文本,但不先登录,因为它应该自动完成.我该怎么办?我试过了
$fb = new Facebook(array(
    'appId'  => 'appid','secret' => 'appsecret','cookie' => true
));


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

我需要做些什么才能使用脚本将其发布到我自己的应用程序墙上?

如果您想发布到自己的应用程序墙,所有您需要的是一个应用程序访问令牌,如果您想在没有登录的情况下发布到用户墙,则还需要此用户长期的实时访问令牌,因为您必须要求离线访问权限

要发布到您的应用程序墙:

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,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/

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...