2015-10-21 38 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,電話號碼等,您可以在數據庫中存儲這些數據。