2014-11-19 4 views
-1

quickblox를 통해 프로그래밍 방식으로 사용자를 만들고 검색하려고합니다. 지금까지 인증 및 세션 생성을 완료했습니다. 그러나이 단계 후에 사용자를 검색하려고하면 토큰이 필요합니다. 오류가 발생합니다.Quickblox 토큰 누락 오류 PHP

DEFINE('APPLICATION_ID', 16619); 
DEFINE('AUTH_KEY', "W4EFMSZx3nQZ7eh"); 
DEFINE('AUTH_SECRET', "NCp5PyZM9uQvWg4"); 

// User credentials 
DEFINE('USER_LOGIN', "removed"); 
DEFINE('USER_PASSWORD', "removed"); 

// Quickblox endpoints 
DEFINE('QB_API_ENDPOINT', "https://api.quickblox.com"); 
DEFINE('QB_PATH_SESSION', "session.json"); 
DEFINE('users', "users.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."&timestamp=".$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 
       )); 




// 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 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 

// Execute request and read response 
$response = curl_exec($curl); 

// Check errors 
if ($response) { 
     $cu = curl_init(); 
curl_setopt($cu, CURLOPT_URL, QB_API_ENDPOINT . '/' . users); 
    curl_setopt($cu, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($cu, CURLOPT_SSL_VERIFYPEER, FALSE); 
$res = curl_exec($cu); 
echo $res; 

} 

내가 JSON 따라서 어떤 도움이 높게 평가 될 것이다

+0

왜 투표해야합니까? –

+0

게시 본 배열에 http 빌드 쿼리를 사용하지 마십시오. Curl은 배열이 전달 될 때 변환을 알고 있습니다. – Anthony

답변

1

세션 생성 요청이 각 추가 요청에 사용해야 세션 토큰을 반환 컬에 새로운 오전 : 여기

는 코드입니다.

그냥 토큰을 설정하면 작동합니다.

+1

OP가 토큰을 어떻게 설정합니까? 게시물 시체에? – Anthony

+0

나는 그것을 이해했다. 토큰은 curl을 사용하여 http 헤더에 QB-TOKEN으로 설정되어야합니다. –

+0

다음 질문에 대한 답변을 주시기 바랍니다. [세션이 만료되었는지 또는 만료되었는지 확인하는 방법?] (http://stackoverflow.com/questions/27074234/how-to-check-whether-session-live-or-expired-in-quickblox-ios-sdk) [ 사용자 필터링 방법?] (http://stackoverflow.com/questions/27060067/how-to-filter-quickblox-users) [전화 번호를 기반으로 사용자를 필터링하는 방법?] (http://stackoverflow.com/ 질문/27055128/how-to-filter-quickblox- 사용자 기반 전화 번호) 미리 감사드립니다 :) @Igor – Hemang