donglao6169 2014-10-16 11:20
浏览 366

cURL请求不发送参数

I'll be honest I'm not 100% knowledgeable with cURL

However I am looking to use it to post an tweet with an image attached to it using Twitters API.

I've got my server script setup to output any $_GET variables. However the array is outputting as blank, So I'm assuming my cURL isnt posting properly.

My PHP code is as follows :

$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);

The $response is returning an error from the Twtter API :

[message] => Your credentials do not allow access to this resource

If I run the URL with all credentials in it in my browser, It works without issue.

Am I missing an additional curl_setopt ?

Cheers

  • 写回答

1条回答 默认 最新

  • duaner5714 2014-10-16 11:38
    关注

    I don't know if this will help but I had to use cURL for Google and YouTube

    I've replaced some of your my vars with yours but it may be worth a try

    <?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 );
    

    Failing that you could try the command line

    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
    
    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)