bar*_*olo 2 facebook facebook-page facebook-graph-api
我改变了我的Facebook页面标签应用程序要求权限的方式.
我正在使用FB Dialog的javascript方法,现在我正在使用重定向方法(其中用户被重定向到FB页面,其中要求权限,然后被重定向回到Facebook页面选项卡).
改变的原因是我相信这种方法比使用javascript对话框会带来更少的错误和问题.
使用重定向方法时,我需要指定在提供权限后用户将被重定向的URL.我想这个网址是安装了应用程序的Facebook页面标签的网址.
构建重定向的URL时,我知道当前的page_id和我的app_id.有了这些信息,我需要构建facebook页面选项卡url,它应该如下所示:
https://www.facebook.com/pages/PAGE-SLUG/ {#APP_ID}?sk = app _ {#APPL_ID}
问题是我不知道什么是PAGE-SLUG.我用上面的url运行的测试(使用PAGE-SLUG作为任何东西)最终重定向到正确的URL.但是,知道Facebook是一个非常不稳定的平台,我想知道有更好的方法来构建这个重定向网址.
编辑:上述方法有问题.默认情况下,当facebook用户不使用SSL时,重定向会丢失SSL协议并使用HTTP链接.
实际上非常简单,您可以使用PHP调用Graph API,如下所示:
$facebook->api("/{PAGE_ID}");
// change {PAGE_ID} to the page id you are redirecting back to
Run Code Online (Sandbox Code Playgroud)
返回值是一个带有"link"的json数组 - >这是你要查找的URL :-)
示例返回:
{
"id": "XXXXXXXXX",
"name": "My Demo Page",
"picture": "",
"link": "https://www.facebook.com/pages/My-Demo-Page/XXXXXXXXX",
"likes": 123456,
"category": "Product/service",
"can_post": true,
"type": "page"
}
Run Code Online (Sandbox Code Playgroud)
如果您知道,也可以按页面名称查询,例如:
通过以下方式查询Graph API:
$facebook->api("/coca-cola");
Run Code Online (Sandbox Code Playgroud)
将导致:
{
"id": "40796308305",
"name": "Coca-Cola",
"picture": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc4/174560_40796308305_2093137831_s.jpg",
"link": "https://www.facebook.com/coca-cola",
"likes": 40680159,
"cover": {
"cover_id": "10150682306963306",
"source": "https://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-snc7/s720x720/416803_10150682306963306_40796308305_9337341_812683101_n.jpg",
"offset_y": 0
},
"category": "Food/beverages",
"is_published": true,
"website": "http://www.coca-cola.com",
"username": "coca-cola",
"founded": "1886",
"description": "Created in 1886 in Atlanta, Georgia, by Dr. John S. Pemberton, Coca-Cola was first offered as a fountain beverage at Jacob's Pharmacy by mixing Coca-Cola syrup with carbonated water. \n\nCoca-Cola was patented in 1887, registered as a trademark in 1893 and by 1895 it was being sold in every state and territory in the United States. In 1899, The Coca-Cola Company began franchised bottling operations in the United States. \n\nCoca-Cola might owe its origins to the United States, but its popularity has made it truly universal. Today, you can find Coca-Cola in virtually every part of the world.",
"about": "The Coca-Cola Facebook Page is a collection of your stories showing how people from around the world have helped make Coke into what it is today.",
"location": {
"latitude": -33.816989983333,
"longitude": 150.84844081667
},
"can_post": true,
"checkins": 80,
"talking_about_count": 297576,
"type": "page"
}
Run Code Online (Sandbox Code Playgroud)
编辑:
一个更清楚的解释:
根据Facebook自己的文档,如果用户决定不接受该应用程序,则不清楚会发生什么.我认为用户将重定向回redirect_uri,然后您可以检查signed_request中是否有"user_id",但我不是100%确定... 创建一个简单的应用程序演示并检查:-)
| 归档时间: |
|
| 查看次数: |
6087 次 |
| 最近记录: |