我改变了我的Facebook页面标签应用程序要求权限的方式。
我正在使用FB Dialog的javascript方法,现在我正在使用重定向方法(其中用户被重定向到一个FB页面,其中会询问权限,然后重定向回到Facebook页面选项卡)。
改变的原因是我相信这种方法会出现 比使用javascript对话框更少的错误和问题。
使用重定向方法时,我需要指定用户在提供权限后重定向的URL。我想这个网址是安装了应用程序的Facebook页面标签的网址。
在构建重定向网址时,我知道当前的 page_id 和我的 app_id 。有了这些信息,我需要构建一个facebook页面标签页面,它应该是这样的:
https://www.facebook.com/pages/PAGE-SLUG/ {#} APP_ID?SK =应用_ {#} APP_ID
问题在于我不知道什么是PAGE-SLUG。我用上面的url运行的测试(使用PAGE-SLUG作为任何东西)最终重定向到正确的URL。但是,知道Facebook是一个非常不稳定的平台,我想知道有更好的方法来构建这个重定向网址。
编辑:上述方法存在问题。当facebook用户默认不使用SSL时,重定向会丢失SSL协议并使用HTTP链接。
答案 0 :(得分:7)
实际上非常简单,你可以用PHP调用Graph API:
$facebook->api("/{PAGE_ID}");
// change {PAGE_ID} to the page id you are redirecting back to
返回值是一个带有“link”的json数组 - >这是你要找的网址: - )
返回示例:
{
"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"
}
您也可以按页面名称查询,如果您知道,例如:
使用以下方法查询Graph API:
$facebook->api("/coca-cola");
将导致:
{
"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"
}
编辑:
更明确的解释:
根据Facebook自己的documentation,如果用户决定不接受该应用程序,则不清楚会发生什么。我认为用户将重定向回redirect_uri,然后您可以检查signed_request中是否有“user_id”,但我不是100%确定... 创建一个简单的应用程序演示并检查:-) 强>