2016-12-23 8 views
1

私はトークンキーの代わりに変数を持っています。変数を使用すると応答は空白になります。トークンキーを使用すると、応答を返します。私が設定した他の変数は問題ではないことを確認しました。問題の変数は私のウェブサイトが、違いはここにあるhttps://geolyft.comトークンの代わりに許可ベアラで許可される変数はありますか?

<!DOCTYPE html> 
<html> 
<head> 
</head> 
<body> 

<?php 
$ltt = $_POST['lat']; 
$lng = $_POST['lng']; 
$token_url = "https://geolyft.com/authentication.php"; 
$token_json = file_get_contents($token_url); 
$curl = curl_init(); 

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://api.lyft.com/v1/drivers?lat=$ltt&lng=$lng", 
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_ENCODING => "", 
    CURLOPT_MAXREDIRS => 10, 
    CURLOPT_TIMEOUT => 30, 
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 
    CURLOPT_CUSTOMREQUEST => "GET", 
    CURLOPT_HTTPHEADER => array(
    "authorization: Bearer $token_json", 
    "cache-control: no-cache", 
    "postman-token: 205a9ff0-102f-7f7a-8f11-b473946cc3fd" 
), 
)); 

$response = curl_exec($curl); 
$err = curl_error($curl); 

curl_close($curl); 

if ($err) { 
    echo "cURL Error #:" . $err; 
} else { 
    echo $response; 
} 
?> 
</body> 
</html> 

です$ token_json

I標識しているものです

CURLOPT_HTTPHEADER => array(
    "authorization: Bearer gAAAAABYXNVPV4B9AEY2bHRZDhB_jw6-hj4ptvUttm45jqroJN0lV5QSZGd-5AL0jrVKod4R5J0Sdxam1Y2nduEO_Lvud8fFGnqAN7shjzgcl9RmLQN5WljEJ9us-Y41_qGr7HT10EH8acseSt-mdO7Dp9MeYaFMkcjIP-IdrIL9uVNll-JypwQgftZ1Bum7gCtQEgpqjGeRuwE4YwE6rLPFALUgZVWNlg==", 
    "cache-control: no-cache", 
    "postman-token: 205a9ff0-102f-7f7a-8f11-b473946cc3fd" 
), 
)); 

私はむしろ代わりに長いトークンキーではなくて、これを持っていますこの設定は空白で、私はしばらく困惑しました。私はおそらく私のリーグから出てくる答えを見つけられないようです。すべてのヘルプは高く評価され

CURLOPT_HTTPHEADER => array(
    "authorization: Bearer $token_json", 
    "cache-control: no-cache", 
    "postman-token: 205a9ff0-102f-7f7a-8f11-b473946cc3fd" 
), 
)); 

答えて

1

私の質問への答えは、他のカールを要求する前に認証カール要求を置くことでした。

$curl = curl_init(); 

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://api.lyft.com/oauth/token", 
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_ENCODING => "", 
    CURLOPT_MAXREDIRS => 10, 
    CURLOPT_TIMEOUT => 30, 
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, 
    CURLOPT_CUSTOMREQUEST => "POST", 
    CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"grant_type\"\r\n\r\nclient_credentials\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"scope\"\r\n\r\npublic\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", 
    CURLOPT_HTTPHEADER => array(
    "authorization: Basic a0JFTE1Oak9QQWY2Om1VZVdwc1lRS0ExUWdfS1dnYTN1OHlHajQxQ3E4LV9X", 
    "cache-control: no-cache", 
    "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", 
    "postman-token: f5d6e662-1663-e577-2c0d-705f03275fa8" 
), 
)); 

$response = curl_exec($curl); 
$err = curl_error($curl); 

curl_close($curl); 

$json = json_decode($response, true); 
$token = $json['access_token']; 
1

使用:

CURLOPT_HTTPHEADER => array(
"authorization: Bearer ".$token_json, 
"cache-control: no-cache", 
"postman-token: 205a9ff0-102f-7f7a-8f11-b473946cc3fd" 
), 
)); 
+0

残念ながら、コードは異なる応答を示しませんでした。応答はまだ空白です。 –

+0

次に、$ token_jsonが実際に値 –

+0

を持っていることを確認します。私がチェックしている方法は、$ token_jsonをエコーし​​てトークン・キーを出していることを確認しています。あなたの努力をありがとう –

関連する問題