我想使用PHP发布消息给Yammer。但是,我无法找到所需的JSON格式的消息。当我使用这一段代码yammer消息json格式
$data=array('body'=>'test from API','group_id'=>'xyz');
$json=json_encode($data);
它说{"body":["Please include a message"]}
是“体”从“消息”不同?
我想使用PHP发布消息给Yammer。但是,我无法找到所需的JSON格式的消息。当我使用这一段代码yammer消息json格式
$data=array('body'=>'test from API','group_id'=>'xyz');
$json=json_encode($data);
它说{"body":["Please include a message"]}
是“体”从“消息”不同?
我能够通过将身体包含在卷曲手柄中来解决这个问题。这为我工作
$curl_handle2="https://www.yammer.com/api/v1/messages.json?access_token=<<accesstoken>>&body=TestingfromAPI&group_id=<<groupid>>";
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $curl_handle2);
curl_setopt($ch2, CURLOPT_POST, true);
$response2 = curl_exec($ch2);
只要看看这个样本 - 很容易实现 https://gist.github.com/aaronroe/3064754
您收到的错误,因为你没有指定的有效载荷是JSON。 您需要添加以下标头: 内容类型:application/json
以下函数是一个示例,显示如何将组标识添加到json载荷以发送给yammer。
function postMessage($token_, $message_, $group_id_) {
$result_ = array() ;
$result_['token'] = $token_ ;
$result_['message'] = $message_ ;
$associativeArray = true ;
$payloadArray_ = array() ;
$payloadArray_['body'] = $message_ ;
if ($group_id_ > 0) {
$payloadArray_['group_id'] = $group_id_ ;
}
try {
$curl_ = curl_init() ;
$headers = array() ;
$headers[] = "Authorization: Bearer " . $token_ ;
$headers[]='Content-Type: application/json' ;
$url = 'https://www.yammer.com/api/v1/messages.json' ;
curl_setopt($curl_, CURLOPT_URL, $url);
curl_setopt($curl_, CURLOPT_POST, true);
curl_setopt($curl_, CURLOPT_POSTFIELDS, json_encode($payloadArray_));
curl_setopt($curl_, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl_);
$result_['response'] = json_decode($response,$associativeArray) ;
} catch (Exception $exception) {
error_log ($exception->getMessage()) ;
$result_['exception'] = $exception->getMessage() ;
}
return $result_ ;
}
是的,这很简单,但是如果您想用缩略图发布视频怎么办?你可以请显示“身体”属性? – 2014-03-04 07:46:01