basecamp中的Message API

时间:2014-05-15 05:34:40

标签: php curl basecamp

使用PHP curl,我试图将消息从php应用程序发布到basecamp。当我运行此代码时,它返回错误,如此

Hmm, that isn’t right
You may have typed the URL incorrectly.
Check to make sure you’ve got the spelling, capitalization, etc. exactly right.

代码

<?php

$username = 'username';
$password = 'password';
$datastring = json_encode(array("name" => "from cURL"));

$URL = "https://basecamp.com/***/api/v1/projects/****.json";

   $ch = curl_init($URL);
   curl_setopt($ch, CURLOPT_MUTE, 1);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
   //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
   curl_setopt($ch, CURLOPT_POSTFIELDS, $datastring);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $output = curl_exec($ch);
   curl_close($ch);
 echo $output;
?>

不确定API网址是否正确?怎么解决?

1 个答案:

答案 0 :(得分:0)

网址看起来不正确 - 您需要检查https://github.com/basecamp/bcx-api/blob/master/sections/messages.md#create-messagehttps://github.com/basecamp/bcx-api/blob/master/sections/comments.md#create-comment是否有添加消息或评论。

要向项目添加新消息,您需要

$URL = "https://basecamp.com/***/api/v1/projects/****/messages.json";