Facebook API:如果用户离线时没有offline_access权限,如何发布到网页Feed [英] Facebook API: How to publish to Page feed while user is offline without offline_access permission

查看:149
本文介绍了Facebook API:如果用户离线时没有offline_access权限,如何发布到网页Feed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Facebook的Graph API,当用户离线时只有publish_stream权限,我已经成功发布到用户的Feed。我不需要offline_access权限。我解释了我在这里的做法:离线时发布Facebook Stream



在用户离线时,我没有成功发布到页面。这是我的场景:



用户U是Page P.的管理员.P授权并安装我的应用程序。 U授权我的应用程序,并授予我以下扩展权限:




  • publish_stream

  • manage_pages



一旦用户离线,如果我尝试使用相同的技术发布到用户的流(不具有offline_access权限),而是发布到页面,我得到一个用户没有授权应用程序执行此操作。这是一个技巧:



1)获取我的应用程序的access_token



2)使用我的应用程序的access_token发布到页面P的Feed:
POST https://graph.facebook.com/ {page_id} / feed



如果在步骤2中使用{user_id}而不是{page_id},那么它会发布给用户的Feed而没有任何问题。但是,我想发布到该页面的Feed。有可能这样做吗?或者我需要用户的offline_access权限才能这样做?



谢谢,
Johnny

解决方案

问题是您需要使用访问令牌来提供通过提前提交的页面。



呃...更简单的方法是这样的:



您的应用程序请求进入manage_pages - 一旦您接受/授予预留,那么您有一个access_token的应用程序预留(离线只会在这里过期= 0)



所以现在你的应用程序有预先管理你的页面,但它需要特定页面的令牌...

所以如果你发出一个 / me / accounts (或 / UID / accounts )与第一个令牌,您将获得应用程序预留访问的页面及其各自的令牌...



从那里只是抓住页面的令牌,然后用该令牌发出您的命令



使用Facebook class( facebook.php 和证书文件)

  require_once'library / facebook.php'; 

$ app_id =YOURAPPID;
$ app_secret =YOURSECRET;

$ facebook = new Facebook(array(
'appId'=> $ app_id,
'secret'=> $ app_secret,
'cookie'= > true
));

$ token = array(
'access_token'=>'来自app / manage_page auth'的令牌
);

$ userdata = $ facebook-> api('/ me / accounts','GET',$ token);

echo'< pre'> ;;
print_r($ userdata);
echo'< / pre>';

您应该会看到一个页面ID列表和他们的访问令牌...



通常我做一个 foreach $ userdata ['data'] 并寻找页面ID,然后我从该子阵列中获取令牌。 ..


Using Facebook's Graph API, I've been successful at publishing to a user's feed while the user is offline with only the publish_stream permission. I don't need the offline_access permission. I explained how I did this here: Facebook Stream Publish while offline

I haven't been as successful with publishing to a Page while the user is offine. Here's my scenario:

User U is an admin of Page P. P authorizes and installs my app. U authorizes my app and grants me the following extended permissions:

  • publish_stream
  • manage_pages

Once the user is offline, if I try the same technique I use to publish to a user's stream (without offline_access permission) to instead publish to a Page, I get a "The user hasn't authorized the application to perform this action". Here's the technique:

1) fetch my app's access_token

2) use my app's access_token to publish to Page P's feed: POST https://graph.facebook.com/{page_id}/feed

If instead of {page_id} in step 2, I use {user_id}, then it publishes to the user's feed without any problem. However, I'd like to publish to the Page's feed. Is it possible to do this? Or do I need the offline_access permission from the user in order to do this?

Thanks, Johnny

解决方案

The problem is you need to use the access token for the page provided via the premissions gained...

Uh... Easier way to say it is this:

Your app requested premission to "manage_pages" - once you accept/grant premission then you have an access_token for the apps premission (offline would just make expires=0 here)

So now your app has premission to manage your pages, but it needs the token for the specific page...

So if you issue a /me/accounts (or /UID/accounts) with the first token you will get a list of the pages the application has premission to access and their respective tokens...

From there just grab the token of the page and then issue your command with that token

Using the facebook class (facebook.php and cert file)

require_once 'library/facebook.php';

$app_id = "YOURAPPID";
$app_secret = "YOURSECRET";

$facebook = new Facebook(array(
    'appId' => $app_id,
    'secret' => $app_secret,
    'cookie' => true
));

$token =  array(
    'access_token' => 'THE Token from app / manage_page auth'
);

$userdata = $facebook->api('/me/accounts', 'GET', $token);

echo '<pre'>;
print_r($userdata);
echo '</pre>';

You should see a llist of page id's and their access tokens...

Usuually i do a foreach $userdata['data'] and look for the page id, then i grab the token from that subarray...

这篇关于Facebook API:如果用户离线时没有offline_access权限,如何发布到网页Feed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆