【问题标题】:Yammer - How to post via api to activity stream? (php)Yammer - 如何通过 api 发布到活动流? (php)
【发布时间】:2012-05-15 20:48:49
【问题描述】:

我能够“获取”活动流,但不能“发布”到它。这似乎是一个技术错误。 这是获取活动流工作的代码:

function getActivityStream()
{
    $as=$this->request('https://www.yammer.com/api/v1/streams/activities.json');
    var_dump($as);
}

function request($url, $data = array())
{
    if (empty($this->oatoken)) $this->getAccessToken();
    $headers = array();
    $headers[] = "Authorization: Bearer " . $this->oatoken['token'];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query($data) );
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    return json_decode($output);
}

好的,这样可以正常工作... 下面的代码,返回一个 Yammer "oops this page could not be found" 消息:

function putActivityStream()
{
    $data=array('type'=>'text', 'text'=>'hello from api test call');
    $json=json_encode($data);
    $res=$this->post('streams/activites.json',$json);
}

function post($resource, $data)
{
    if (empty($this->oatoken)) $this->getAccessToken();
    $ch = curl_init();
    $headers = array();
    $headers[] = "Authorization: Bearer " . $this->oatoken['token'];
    $headers[]='Content-Type: application/json';
    $url = 'https://www.yammer.com/api/v1/' . $resource;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    $response = curl_exec($ch);
    return $response;
}

其中一个例子来自: http://developer.yammer.com/api/streams.html

POST https://www.yammer.com/api/v1/streams/activities.json
Requests must be content-type: application/json.

{
  "type": "text",
  "text": "The build is broken."
}

【问题讨论】:

    标签: php curl yammer


    【解决方案1】:

    你会踢自己的。您的代码中有错字。 :) 变化:

    $res=$this->post('streams/activites.json',$json);
    

    $res=$this->post('streams/activities.json',$json);
    

    简单。

    【讨论】:

      猜你喜欢
      • 2018-07-31
      • 1970-01-01
      • 1970-01-01
      • 2015-02-20
      • 1970-01-01
      • 2014-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多