2014-01-21 65 views
0

我試着用下面的代碼,但它顯示一個錯誤,說:如何在soundcloud php api中驗證http響應代碼?

CODE:

if (isset($_GET['code'])) 
{ 
    $soundcloud->_validResponseCode($_GET['code']); 
    $_SESSION['access_token'] = $soundcloud->accessToken($_GET['code']); 
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']); 
} 

錯誤:

Fatal error: Call to protected method Services_Soundcloud::_validResponseCode() 

回答

0

使用try catch塊,然後您可以通過HTTP代碼例外,例如:

// check the status of the relationship 
try { 
    $client->get('/me/followings/3207'); 
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { 
    if ($e->getHttpCode() == '404') 
     print "You are not following user 3207\n"; 
} 
+0

我在這裏要做的是驗證我在連接到soundcloud後返回的代碼...在回調頁中... – Tej

+0

@Tej我認爲你應該認爲它是好的,除非拋出異常,沒有什麼問題。您無法訪問httpcode/responsecode屬性/方法,因爲它們是私人/受保護的 –