使用cURL twitter获取空白页面


Getting blank page using cURL twitter

我正在尝试使用PHP w/Codeigniter框架添加一个twitter帐户
我得到了一个空白页,没有任何错误,甚至在我的日志中都没有。承载令牌是可以的,我直接将其添加到代码中进行测试。

我做错了什么?感谢您的帮助。谢谢

控制器:manage.php

   if($_POST['platform'] == 'twitter'):
  $request = curl_init();
    $bearer = "AAAAAAAAAAAAAAAAAAAAAJ%xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 
    curl_setopt($request, CURLOPT_SSLVERSION, 3);
    curl_setopt($request, CURLOPT_URL, 'https://api.twitter.com/1.1/application/rate_limit_status.json');
    curl_setopt($request, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$bearer));
    curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
    $result = json_decode($content = curl_exec($request));
    curl_close($request);
    return($result);
    if($request == 0):
       $error = 'Sorry, rate limited';
    else:
        $account_data = @file_get_contents('http://api.twitter.com/1.1/users/show.json?screen_name='.$_POST['account_id'].'&include_entities=true');
        $account_data = json_decode($account_data);
    endif;
    if($account_data != false):
        $new_account = array(
            'id' => $account_data->screen_name,
            'username' => $account_data->screen_name,
            'name' => $account_data->name,
            'link' => 'https://twitter.com/'.$account_data->screen_name,
            'picture' => $account_data->profile_image_url,
            'platform' => 'twitter'
        );
    else:
        $error = "Account Not Found";
    endif;

视图:add.php

   <?php
   if(isset($error)) echo "<p>".$error."</p>";
echo '<form action="/manage/add" method="post" accept-charset="utf-8" style="margin-left:-15px; margin-top:-15px;">';
echo form_error('account_id');
echo '<strong>'.form_label('Account ID', 'account_id');
echo form_input('account_id', set_value('account_id', ''),'style="width: 288px;"');
    echo form_label('Platform', 'platform');
    echo form_dropdown('platform', $platforms, set_value('platform', $this->input->post('platform')));
$data = array('name' => 'submit', 'value' => 'Add Account', 'class' => 'submit');
echo form_submit($data);
  ?>
   <?php echo form_close(); ?>

当我将其设置为CURLOPT_RETURNTTRANSFER时,我得到false

{"rate_limit_context":{"application":"N3KVVzpE8d0qapC6kJJSw"},"resources":{":15,"重置":1373460189},"/lists/suubscriptions":{"limit":15,"remaining":15、"reset":1373460189}、"/lists/members":{"limit":15,"remaining":15、"remainsing":137346019}、"/lists/status":{89},"/lilists/members/show":{"limit":15,"remaining":15、"reset":1373460189}}、"application":{"/application/rate_limit_status":{"limit":180、"remained":169、"resete":1373459343}、"friendships":{,"/users/建议/:slug/members":{"limit":15,"remaining":15、"reset":1373460189},"/users/show/:id":{15,"重置":1373460189}},"followers":{"/followers/list":{"limit":30,"remaining":30":60","剩余":60,"重置":1373460189},"/status/user_timeline":{"limit":300,"remaining":300、"reset":1373460189}、"/status/sretweets/:id":{剩余":15,"重置":1373460189},"/help/languages":{"limit":15,"remaining":15、"reset":1373460189}:450,"剩余":450,《重置》:1373460189}},"trends":{"/trends/available":{"limit":15,"remaining":15

您的Authorization头看起来有问题。要执行这种请求,您需要生成一个签名。推特开发网站上有更多信息

我写了一个CodeIgniter库,用于向Twitter发出cURL请求。你可能想使用它,或者只是从中提取一些代码

我已经解决了这个问题。

  $request = curl_init();
    $bearer = "AAAAAAAAAAAAAAAAAAAAAJ%2xxxxxxxxxxxxxxx0x0x0x0x0x0x0x0x0x0xxxxxx"; 
    curl_setopt($request, CURLOPT_SSLVERSION, 3);
    curl_setopt($request, CURLOPT_URL, 'https://api.twitter.com/1.1/users/show.json?screen_name='.$account_id.'&include_entities=true');
    curl_setopt($request, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$bearer));
    curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
    $account_data = json_decode($file_get_contents = curl_exec($request)); 
    curl_close($request);