首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Twitter Digit API不工作CURL php

Twitter Digit API不工作CURL php
EN

Stack Overflow用户
提问于 2015-10-21 11:45:58
回答 1查看 130关注 0票数 1

我正在与twitter digit合作。我的手机验证工作正常。但是有了auth头信息,当我调用curl时,它就不是working.my curl代码了

代码语言:javascript
复制
$request=$_REQUEST['someData'];


function oauth_value($headersIndex = [])
{
    if(empty($headersIndex)) return 'Invalid Index Number';

    $value = explode('=', $headersIndex);
    return str_replace('"', '', $value[1] );
}

$headersData = explode(',',$request['headers']);

$ch = curl_init();


$ch = curl_init($request['apiUrl']);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization' => 'OAuth oauth_consumer_key="'.oauth_value($headersData[0]).'",
     oauth_nonce="'.oauth_value($headersData[1]).'",
      oauth_signature="'.oauth_value($headersData[2]).'",
       oauth_signature_method="HMAC-SHA1", 
       oauth_timestamp="'.oauth_value($headersData[4]).'", 
       oauth_token="'.oauth_value($headersData[5]).'",
       oauth_version="'.oauth_value($headersData[6]).'"'
  )
);

$resp = curl_exec($ch);

$info = curl_getinfo($ch);
curl_close($ch);

来自$_REQUEST‘’someData‘的示例信息;

代码语言:javascript
复制
Array
(
    [apiUrl] => https://api.digits.com/1.1/sdk/account.json
    [headers] =>
     OAuth oauth_consumer_key="OybCXYoYTuS0Cw0usZYry6Nlj", 
    oauth_nonce="3942830480-TILitVHHZGmcczuuFj3nbJtnMm00DHvvgduawMHOybCXYoYTuS0Cw0usZYry6Nlj1445246231940",
     oauth_signature="dXHcH%2FsLBIlYOVWBIhEBWSCMLJo%3D",
      oauth_signature_method="HMAC-SHA1",
     oauth_timestamp="1445246231", 
     oauth_token="3942830480-TILitVHHZGmcczuuFj3nbJtnMm00DHvvgduawMH",
      oauth_version="1.0"
)

我现在能做什么?

EN

回答 1

Stack Overflow用户

发布于 2016-12-16 15:41:01

如果你有一个URL和来自数字的标题,那么你可以使用下面的代码:

代码语言:javascript
复制
$apiUrl = 'https://api.digits.com/1.1/sdk/account.json';
$authHeader = 'OAuth oauth_consumer_key="**********", oauth_nonce="****", oauth_signature="****", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1481554529", oauth_token="*****", oauth_version="1.0"';

// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Authorization: {$authHeader}"
  )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents($apiUrl, false, $context);

$final_output = array();
if($file)
{
    $final_output = json_decode($file,true);
}
print_r($final_output);

它将返回id_str、电话号码等。您可以将这些数据存储在数据库中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33250579

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档