post Facebook 页面的图像或状态 api
post image or status with facebook page with api
从昨天开始,我尝试 post 带有图像(或不带有图像)的状态与带有 facebook 图的 facebook 页面 api。
客户端连接到此范围:
email, public_profile, manage_pages, user_posts, publish_actions, 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
Select“Facebook 应用程序”:您的应用程序
Select“用户或页面”:用户令牌(获取用户访问令牌)
Select权限:“pages_manage_posts”
点击复制访问令牌:
- => 短期用户访问令牌:SLUATOKEN
获取长期用户访问令牌
-
转到https://developers.facebook.com/apps/
Select App -> Setting -> Basic -> Get App ID, App Secret
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
获取长期页面令牌
-
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
Post状态
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 页面
检查令牌过期时间
从昨天开始,我尝试 post 带有图像(或不带有图像)的状态与带有 facebook 图的 facebook 页面 api。
客户端连接到此范围:
email, public_profile, manage_pages, user_posts, publish_actions, 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
Select“Facebook 应用程序”:您的应用程序
Select“用户或页面”:用户令牌(获取用户访问令牌)
Select权限:“pages_manage_posts”
点击复制访问令牌:
- => 短期用户访问令牌:SLUATOKEN
获取长期用户访问令牌
-
转到https://developers.facebook.com/apps/
Select App -> Setting -> Basic -> Get App ID, App Secret
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
获取长期页面令牌
-
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
-
Post状态
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 页面
检查令牌过期时间