2015-10-21 79 views
1

我正在使用twitter数字。我的移动验证工作正常。但与AUTH标题信息当我打电话卷曲那么它不working.my卷曲代码,来形成$ _REQUESTTwitter数字API不工作CURL php

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

例如信息[“someData”];

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" 
) 

现在能做什么?

回答

0

如果从数字的URL和标题,那么你可以使用下面的代码:

$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,电话号码等,您可以在数据库中存储这些数据。