开发者

Facebook Dashboard API.... fail to use it :|

开发者 https://www.devze.com 2022-12-18 09:17 出处:网络
This question is about Dashboard.addNews and Dashboard.publishActivity Facebook has told the public about its new Dashboard API, however it hasn\'t provided any updates on its library to use the new

This question is about Dashboard.addNews and Dashboard.publishActivity

Facebook has told the public about its new Dashboard API, however it hasn't provided any updates on its library to use the new code.

So I followed the advice in this link http://forum.developers.facebook.com/viewtopic.php?pid=197753 to add the new functions to the facebookapi_php5_restlib.php

//dashboard functions
  public function dashboard_addNews($uid, $news, $image = null) { 
    return $this->call_method('facebook.dashboard.addNews',
                              array('uid' => $uid,
                                    'news' => $news,
                                    'image' => $image));
  }

  public function dashboard_multiAddNews($uids, $news, $image = null) { 
    return $this->call_method('facebook.dashboard.multiAddNews',
                              array('uids' => $uids ? json_encode($uids) : null,
                                    'news' => $news,
                                    'image' => $i开发者_JAVA百科mage));
  }

  public function dashboard_addGlobalNews($news, $image = null) {
    return $this->call_method('facebook.dashboard.addGlobalNews',
                              array('news' => $news,
                                    'image' => $image));
  }

  public function dashboard_publishActivity($activity, $image = null) {
    return $this->call_method('facebook.dashboard.publishActivity',
                              array('activity' => $activity,
                                    'image' => $image));
  }

  public function dashboard_multiIncrementCount($uids) {
    return $this->call_method(
      'facebook.dashboard.multiIncrementCount', array('uids' => json_encode($uids)));
  }

  public function dashboard_removeActivity($activity_ids) {
    return $this->call_method(
      'facebook.dashboard.removeActivity', array('activity_ids' => json_encode($activity_ids)));
  }

  public function dashboard_setCount($uid, $count) {
    return $this->call_method('facebook.dashboard.setCount',
                              array('uid' => $uid,
                                    'count' => $count));
  }

But now when I follow the sample code at http://wiki.developers.facebook.com/index.php/Dashboard.addNews

$image = 'http://www.martialdevelopment.com/wordpress/wp-content/images/cheezburger-or-dim-mak.jpg'; 
$news = array(array('message' => 'Your friend @:563683308 just sent you a present!', 'action_link' => array('text' => 'Get Your Gift', 'href' => 'http://www.example.com/gifts?id=5878237'))); 
$facebook->api_client->dashboard_addNews($user_id, $news, $image);

However it will prompt this error:

[Wed Jan 27 03:42:27 2010] [error] [client 127.0.0.1] PHP Notice:  Array to string conversion in /var/local/site/webroot/xxxx/facebookapi_php5_restlib.php on line 2009

the code at that php line is

if (is_array($val)) $val = implode(',', $val);

pls notice that I haven't altered the facebookapi_php5_restlib.php except pasting those suggested dashboard function code.

and when I follow the instruction at http://wiki.developers.facebook.com/index.php/Dashboard.publishActivity and try to use it:

$image = 'http://www.martialdevelopment.com/wordpress/wp-content/images/cheezburger-or-dim-mak.jpg'; 
$activity = array(array('message' => '{*actor*} just sponsored @:563683308!', 'action_link' => array('text' => 'Sponsor this cause', 'href' => 'http://www.example.com/games?id=5878237'))); 
$facebook->api_client->dashboard_publishActivity($activity, $image);

it throws out the same error too about "Array to string conversion"

Any suggestion to actually use the new Facebook Dashboard API?


If you don't assign into the same variable, the warning will likely go away:

if (is_array($val)) $stringval = implode(',', $val); 


Okay, I found that no need to modify the php class at all.

All we need to do is use the call_method

$news = array(array('message' => 'There is a new level in the dungeon!', 'action_link' => array('text' => 'Play now.', 'href' => 'http://www.example.com/gifts?id=5878237'))); 
$facebook->api_client->call_method('facebook.dashboard.addGlobalNews', array('news' => $news));
0

精彩评论

暂无评论...
验证码 换一张
取 消