Think in G

Never stop ThinkinG…

Archive for the ‘SNS’ Category

设置Facebook应用的post authorize redirect url

without comments

最近在做Facebook的app,想要实现这么一个动作:当用户加入这个应用后,能够重定向到指定的callback页面,让应用能够收到用户使用该应用的通知。

但找了许久,发现网上很多文章中提到的post-add url 已经从应用设置页面中消失了。
怎么办?在google的帮助下,终于在这里找到了些线索。虽然在设置页面中找不到这个callback的设定,但是这个设置依然存在(在官方的Application Properties页面中可以找到这个 post_authorize_redirect_url),并且可以通过Legacy REST API写入。

马上从官网下载了PHP SDK,试了试,代码如下:

<?php
// Set the post_authorize_redirect_url
// The facebook.php is the official PHP SDK.
require_once __DIR__ . '/facebook.php';

// Create our Application instance.
$facebook = new Facebook(array(
  'appId' => {app_key},
  'secret' => {app_secret},
  'cookie' => true,
));

$args = array("post_authorize_redirect_url"
            => {put your post authorize redirect url HERE. } );

try {
      $properties = array(
        'method' => 'admin.setAppProperties',
        'properties' => $args,
      );
      $result = $facebook->api($properties);
      printf($result);
} catch (FacebookApiException $e) {
      error_log($e);
}

设置完成后,测试了一下自己的应用,确实能够成功跳转了。
最后,忍不住吐槽一下。调查Facebook应用有好几天了,发现Facebook的API以及SDK虽然功能强大,但是相当混乱,而且不时会看到deprecated的内容,很多细节和workaround都没有记述在文档中,就像在RPG里搜罗隐藏宝物。看来这真是一个计划赶不上变化的时代!

分享家:Addthis中国

Written by ghawk.gu

March 29th, 2011 at 6:50 pm