代码之家  ›  专栏  ›  技术社区  ›  Unreality

Facebook Dashboard API…无法使用:|

  •  0
  • Unreality  · 技术社区  · 16 年前

    这个问题是关于 仪表板.addnews 和 仪表板.发布活动

    Facebook已经向公众介绍了其新的仪表板API,但它还没有在其库中提供任何使用新代码的更新。

    所以我遵循了这个链接中的建议 http://forum.developers.facebook.com/viewtopic.php?pid=197753 将新函数添加到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' => $image));
      }
    
      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));
      }
    

    但是现在当我按照下面的示例代码 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);
    

    但是,它将提示此错误:

    [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
    

    该PHP行的代码是

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

    请注意,除了粘贴那些建议的仪表板功能代码之外,我没有修改facebookapi_php5_restlib.php。

    当我按照指示 http://wiki.developers.facebook.com/index.php/Dashboard.publishActivity 尝试使用它:

    $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);
    

    对于“数组到字符串的转换”,它也会抛出相同的错误。

    有没有建议实际使用新的Facebook Dashboard API?

    2 回复  |  直到 11 年前
        1
  •  0
  •   great_llama    16 年前

    如果不给同一个变量赋值,警告可能会消失:

    if (is_array($val)) $stringval = implode(',', $val); 
    
        2
  •  0
  •   Unreality    16 年前

    好吧,我发现根本不需要修改PHP类。

    我们只需要使用call_方法

    $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));
    
    推荐文章