使用api在facebook页面上发布图片或状态
post image or status with facebook page with api
从昨天开始,我尝试用带有facebook图形api的facebook页面发布带有图像(或不带有图像)的状态。
客户端连接到此范围:
电子邮件、public_profile、manage_pages、user_posts、publish_action、publish_pages
我把这个函数称为
postPicture = () => {
FB.api("/231713458314438/feed",
"POST",
{
"link": "http://ichef-1.bbci.co.uk/news/660/cpsprodpb/17A21/production/_85310869_85310700.jpg",
"message": "test"
},
function (response) {
console.log(response)
}
);
}
出版物已发布,但我的个人帐户在页面上,而不是在管理页面上。
所以你知道如何用页面发布状态吗?
根据此处的文档:https://developers.facebook.com/docs/graph-api/overview/
您还需要将为登录的管理员生成的access_token
作为参数请求传递:
postPicture = () => {
FB.api("/231713458314438/feed",
"POST",
{
"link": "http://ichef-1.bbci.co.uk/news/660/cpsprodpb/17A21/production/_85310869_85310700.jpg",
"message": "test",
"access_token": {your-access-token}
},
function (response) {
console.log(response)
}
);
}
-
从Facebook门户网站获取用户访问令牌
-
https://developers.facebook.com/tools/explorer
选择";Facebook应用程序":你的应用
选择";用户或页面":用户令牌(获取用户访问令牌)
选择权限:"pages_manage_posts";
点击复制访问令牌:
- =>短期用户访问令牌:SLUATOKEN
-
-
获取长期用户访问令牌
-
https://developers.facebook.com/docs/facebook-login/access-tokens/refreshing#get-a长期用户访问
转到https://developers.facebook.com/apps/
选择应用程序->设置->基本->获取应用程序ID,应用程序机密
curl -i -X GET "https://graph.facebook.com/{graph-api-version}/oauth/access_token? grant_type=fb_exchange_token& client_id={app-id}& client_secret={app-secret}& fb_exchange_token={Short-Lived User Access Token}"
=>卷曲:
curl -i -X GET "https://graph.facebook.com/v10.0/oauth/access_token?grant_type=fb_exchange_token&client_id=APPID&client_secret=APPSECRET&fb_exchange_token=SLUATOKEN"
- =>获得长期用户访问令牌:LONGLIVEDUATOKEN
-
-
获取用户ID
-
步骤4 中需要用户ID
curl -i -X GET "https://graph.facebook.com/v10.0/me?fields=id%2Cname&access_token={Long-Live User Access Token}"
=>卷曲:
curl -i -X GET "https://graph.facebook.com/v10.0/me?fields=id%2Cname&access_token=LONGLIVEDUATOKEN"
- =>已获取用户ID:YOURFBID
-
-
获取长寿页面令牌
-
https://developers.facebook.com/docs/facebook-login/access-tokens/refreshing#get-a-长时间的页面访问
curl -i -X GET "https://graph.facebook.com/{graph-api-version}/{user-id}/accounts?access_token={Long-Lived User Access Token}"
=>卷曲:
curl -i -X GET "https://graph.facebook.com/v10.0/YOURFBID/accounts?access_token=LONGLIVEDUATOKEN"
- =>获得长寿页面令牌:LONGLIVEDPAGEACCESSTOKEN
-
-
张贴状态
-
https://developers.facebook.com/docs/graph-api/reference/page/feed/#publish
=>卷曲:
curl -i -X POST "https://graph.facebook.com/v10.0/feed?message=This_Is_My_New_Status&access_token=LONGLIVEDPAGEACCESSTOKEN"
- =>完成!查看你的Facebook页面
-
-
检查令牌过期时间
- https://developers.facebook.com/tools/debug/accesstoken/?access_token=LONGLIVEDPAGEACCESSTOKEN&版本=v10.0
- 您将看到:
Expires: Never
- 您将看到:
- https://developers.facebook.com/tools/debug/accesstoken/?access_token=LONGLIVEDPAGEACCESSTOKEN&版本=v10.0
- 在Shopify中获取博客文章的图片
- 图片照片库
- 事件和状态
- 知道为什么我的旋转木马不会自动更改图片吗
- PHP AJAX图片上传示例不上传
- 获取选择框的状态
- 相位器状态未捕获参考错误
- 如何更改reactjs中外部/独立组件的状态或属性
- 如何使用密码检测网络中的状态连接
- Ember.js-接口状态应该存储在哪里
- 混合 ui-sref 和 $state.go 在 Angular ui-router 中进行状态转换
- 在Angular 2中布线期间保持零部件处于活动状态
- 在mvc应用程序中,在回发时保留最初隐藏的文本框的隐藏或可见状态
- XMLHttpRequest未返回值-状态202
- 使用javascript反复检查用户在facebook上的登录状态
- 如何使bxslider仅在移动视图中处于活动状态
- 获取ASP.NET Ajax Timer状态
- React redux初始化功能,无论状态变化如何
- 使用api在facebook页面上发布图片或状态
- 如何做简单的Facebook状态帖子与文字和图片