我正在使用 Graph API 代码,该代码使用一个 acces_token
和一个具有发布到粉丝页面权限的 id_page
。只要用户登录,它就可以工作,但是当我注销时,access_token
过期,我无法发布到粉丝页面。
如何使我的应用程序能够随时发布,即使用户未登录也是如此?
这是我的代码:
<?php
$page_access_token = 'AAAFNxxxx';
$page_id = '15203xxx';
$data['picture'] = "https://www.google.it/logos/2012/moby_dick12-hp.jpg";
$data['link'] = "http://www.google.it/";
$data['message'] = "Test";
$data['description'] = "Lorem ipsum dolor sit amet";
$data['access_token'] = $page_access_token;
//curl connection
$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch); ?>
最佳答案
您可以使用 extended token在用户注销时发布,通过检索相同的交换您自己的 client_id(您的 app_id)、您的 app_secret 和未过期的短期 access_token
https://graph.facebook.com/oauth/access_token?
client_id=APP_ID&
client_secret=APP_SECRET&
grant_type=fb_exchange_token&
fb_exchange_token=EXISTING_ACCESS_TOKEN
关于facebook-graph-api - 在用户未登录时在 Facebook 粉丝页面上发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12952631/