gpt4 book ai didi

php - Yammer - 如何通过 api 发布到事件流? (PHP)

转载 作者:行者123 更新时间:2023-12-04 05:46:32 27 4
gpt4 key购买 nike

我能够“获取”事件流,但不能“发布”到它。看来是技术错误。
这是用于获取事件流的代码:

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 “哎呀,找不到这个页面”信息:
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."
}

最佳答案

你会踢自己。你的代码有错别字。 :)
改变:

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


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

简单。

关于php - Yammer - 如何通过 api 发布到事件流? (PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10608689/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com