2014-10-16 63 views
0

我會說實話我不是100%掌握相關捲曲捲曲請求不發送PARAMATERS

但是我期待用它來發佈一個鳴叫使用Twitter的API連接到它的圖像。

我有我的服務器腳本設置輸出任何$ _GET變量。然而數組輸出爲空白,所以我假設我的cURL沒有正確發佈。

我的PHP代碼如下:

$url = 'http://www.website.com/tweet.php'; 

$myvars = 'access_token=' . $access_token . '&access_token_secret=' . $access_token_secret . '&message=' . $message . '&image=' . $image; 

$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

$response = curl_exec($ch); 

output($response); 

的$響應返回從Twtter API的錯誤:

[消息] =>您的憑據不允許訪問此資源

如果我在瀏覽器中運行包含所有憑證的URL,它的工作沒有問題。

我是否缺少額外的curl_setopt?

乾杯

+0

嘗試爲您瓦爾數組並傳遞數組到CURLOPT_POSTFIELDS – AdRock 2014-10-16 11:27:33

+0

嗨@AdRock我已經這樣做,沒有區別.. Unfortunatley – StuBlackett 2014-10-16 11:30:52

回答

1

我不知道這是否會幫助,但我不得不使用捲曲的谷歌和YouTube

我已經更換了一些你我瓦爾與你的,但它可能是值得一試

<?php 
// init the resource 
$access_token = ''; 
$access_token_secret = ''; 
$message = ''; 
$image = ''; 

$url = 'http://www.website.com/tweet.php'; 

$clienttoken_post = array(
    "access_token" => $access_token, 
    "access_token_secret" => $access_token_secret, 
    "message" => $message, 
    "image" => $image 
); 

$curl = curl_init($url); 

curl_setopt($curl, CURLOPT_POST, true); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post); 
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 

$json_response = curl_exec($curl); 
curl_close($curl); 

print_r($json_response); 

如果做不到這一點,你可以嘗試在命令行

curl --data "access_token=YOUR_ACCESS_TOKEN&access_token_secret=YOUR_ACCESS_TOKEN_SECRET&message=YOUR MESSAGE&image=YOUR_IMAGE" http://www.website.com/tweet.php