2012-09-21 73 views
1

我试图获得与REST API的应用程序状态和我有一点无法得到它返回好数据Heroku JSON REST API的PHP示例?

$ch = curl_init(); 

    curl_setopt($ch, CURLOPT_URL, 'https://api.heroku.com'); // No clue what to put here. 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_USERPWD, ":yesthisismyrealapikeyanditworks"); // trust me on this line :) 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json')); //total guess 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'https://api.heroku.com/apps/myapp/ps'); // where myapp is actually my app name 

    // Getting results 
    return curl_exec($ch); 

这还没有恢复任何有用的东西。我是JSON和卷曲的新手,请尽量轻松一点。谢谢。

戴夫

+0

_ “这还没有恢复任何用处。” _ - 确定。那么它返回的是什么? –

+0

对不完整的问题。我收到了一些返回数据,其中一种情况是为我创建新的dynos,而不是发送ps状态。虽然没有任何有用的错误。 –

回答

1
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://api.heroku.com/apps/myapp/ps'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERPWD, ":yesthisismyrealapikeyanditworks"); 
return curl_exec($ch); 
+0

是的!这工作。我绕着轴转换linux风格的curl命令到PHP。我从命令行看到好的结果 curl -H“Accept:application/json”-u:myapikey -X GET https://api.heroku.com/apps/myapp/ps 但是搞不清楚如何进入PHP的跳跃。 –