一直使用PHP脚本来读取自定义对象数周。今天我开始得到{"错误":["未经授权"]}回复。我仍然可以使用Web门户和相同的凭据登录。使用相同的QuickBlox应用程序,Android应用仍可正常运行。一直在挠我的头..有人可以帮忙吗?
代码:
<?php
// Application credentials - change to yours (found in QB Dashboard)
DEFINE('APPLICATION_ID', 99999);
DEFINE('AUTH_KEY', "AbCd...");
DEFINE('AUTH_SECRET', "ZxYvW...");
// User credentials
DEFINE('USER_LOGIN', "user@domain.com");
DEFINE('USER_PASSWORD', "password");
// Quickblox endpoints
DEFINE('QB_API_ENDPOINT', "https://api.quickblox.com");
DEFINE('QB_PATH_SESSION', "session.json");
// Generate signature
$nonce = rand();
$timestamp = time(); // time() method must return current timestamp in UTC but seems like hi is return timestamp in current time zone
$signature_string = "application_id=".APPLICATION_ID."&auth_key=".AUTH_KEY."&nonce=".$nonce."×tamp=".$timestamp."&user[login]=".USER_LOGIN."&user[password]=".USER_PASSWORD;
echo "stringForSignature: " . $signature_string . "<br><br>";
$signature = hash_hmac('sha1', $signature_string , AUTH_SECRET);
// Build post body
$post_body = http_build_query(array(
'application_id' => APPLICATION_ID,
'auth_key' => AUTH_KEY,
'timestamp' => $timestamp,
'nonce' => $nonce,
'signature' => $signature,
'user[login]' => USER_LOGIN,
'user[password]' => USER_PASSWORD
));
echo "postBody: " . $post_body . "<br><br>";
// Configure cURL
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, QB_API_ENDPOINT . '/' . QB_PATH_SESSION); // Full path is - https://api.quickblox.com/session.json
curl_setopt($curl, CURLOPT_POST, true); // Use POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body); // Setup post body
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Receive server response
// Execute request and read response
$response = curl_exec($curl);
// Check errors
if ($response) {
echo $response . "\n";
} else {
$error = curl_error($curl). '(' .curl_errno($curl). ')';
echo $error . "\n";
}
$jsonResponse = json_decode($response,true);
$qbToken = $jsonResponse['session']['token'];
答案 0 :(得分:0)
1.首先,您需要检查您在脚本中传递的quickblox凭证,如appId,authKey
2.然后需要检查用户是否在同一个quickblox帐户中注册。
3.还有一件事需要知道,在php中,快速帐户的密码应该超过8个字符。