2013-07-24 44 views
1

我想在我的iOS應用程序中驗證用戶,但是我得到的只是一個400錯誤Disqus Password Credentials OAuth

按照documentation「這種類型的流量僅限於批准的應用程序,讓你必須先請求訪問

那麼如何批准我的應用程序才能完成此流程?我請求

部分:

NSURL *url = [NSURL URLWithString:@"https://disqus.com/api/oauth/2.0/access_token/"]; 
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:WS_TIMEOUT]; 

NSString *strAuth = [NSString stringWithFormat:@"%@:%@", username, password]; 
NSString *strAuthBase64 = [[strAuth dataUsingEncoding:NSUTF8StringEncoding] base64EncodedString]; 

NSString *postString = [NSString [email protected]"grant_type=password&client_secret=%@&client_id=%@&scope=read,write", DISQUS_SECRET, DISQUS_KEY]; 

[request addValue:[NSString stringWithFormat:@"Basic %@", strAuthBase64] forHTTPHeaderField:@"Authorization"]; 
[request setHTTPMethod:@"POST"]; 
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; 

在此先感謝。

回答

3

這是我們必須從我們的最終啓用您的應用程序。但是,我會建議託管一個頁面來處理標準服務器端流的身份驗證。然後,您可以在用戶授權後,將訪問令牌和其他變量從頁面拖到您的應用程序中。

原因是您不必處理表單驗證,錯誤消息傳遞,並且可以利用我們對錶單的更新而無需觸摸代碼。

在PHP和Python一些服務器端的OAuth例子可在這個網頁上找到:https://github.com/disqus/DISQUS-API-Recipes/tree/master/oauth