2012-07-08 47 views
0

UPDATE:Web客戶端失敗的物理設備和仿真器

Maybe it's just me not understanding how oAuth works? I tried running the query manually on http://www.apikitchen.com and I get a 400 error there too! Just to be sure, am I constructing the URL correctly here?

POST URL:

https://api.bufferapp.com/1/oauth2/token.json?client_id=[hidden]&client_secret=[hidden]&redirect_uri=http://apps.joel-murphy.com/buffer/code/success.php&code=[the access code I get from buffer starting with 1/]&grant_type=authorization_code

原帖:

我建立這需要從一個網站數據使用的Windows Phone應用程序。該網站使用oAuth來驗證用戶身份。

我使用內置的Web瀏覽器控件進行GET請求來驗證用戶身份。官方文檔要求URL結構如下:

GET https://bufferapp.com/oauth2/authorize ? client_id=...& redirect_uri=...& response_type=code

我的應用程序的這部分工作。雖然從服務器交換訪問令牌的授權令牌時,我遇到了問題。官方文檔需要的URL結構是這樣的:

POST https://api.bufferapp.com/1/oauth2/token.json ? client_id=...& client_secret=...& redirect_uri=...& code=...& grant_type=authorization_code

糾正我,如果我錯了,但是從我知道有沒有辦法使從瀏覽器POST請求,除非提交表單。出於這個原因,我決定使用WebClient類將數據提交給服務器。

The remote server returned an error: NotFound

enter image description here

沒有人有任何的想法有什麼不對下面的代碼:但是,不管我在實際設備上或在Visual Studio模擬器我總是收到以下錯誤運行我的代碼?我花了超過5個小時,試圖解決這個錯誤,但似乎沒有任何工作。

我正在使用的代碼:

WebClient wc = new WebClient(); 
    wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted); 

    wc.UploadStringAsync(new Uri(access_token_url), "POST", GetPostParameters()); 


    void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e) 
    { 
     try 
     { 
      MessageBox.Show(e.Result); 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.Message); 
     } 
    } 

    string GetPostParameters() 
    { 
     string data = ""; 
     data += "client_id="+client_id + "&"; 
     data += "client_secret=" +client_secret + "&"; 
     data += "redirect_uri=" + redirect_uri+ "&"; 
     data += "code=" + App.AccessToken + "&"; 
     data += "grant_type=authorization_code"; 
     return data; 
    } 

沒有人有任何的想法有什麼不對?這讓我瘋狂起來,這真是讓人羞恥,因爲現在這種技術已經成爲現實,oauth必須如此複雜。

在此先感謝。

+1

有幾個OAuth包裝器[包括這一個](http://localangle.codeplex.com/SourceControl/changeset/view/17743#210860)可以簡化整個過程 - 它可能是值得使用類似的東西以解決簽署問題 – 2012-07-08 17:23:56

+0

乾杯隊友,我現在檢查一下,並儘快報告:) – 2012-07-08 17:24:44

+0

我在我的解決方案中添加了OAuthWebRequest類,但它包含99個錯誤,我不知道如何解決:(謝謝無論如何 – 2012-07-08 17:38:04

回答

0

你可以嘗試URL編碼redirect_uri變量?

+0

感謝您的回覆。我嘗試將代碼更改爲此,但我仍然得到完全相同的錯誤:data + =「redirect_uri =」+ HttpUtility.UrlEncode(redirect_uri)+「&」; – 2012-07-08 15:30:00

+0

我剛更新了OP,do你認爲你可以快速瀏覽一下嗎? – 2012-07-08 15:50:50

+1

你沒有在更新的文章中編碼你的URL,編碼的URL應該是http%3A%2F%2Fapps.joel-mur phy.com%2Fbuffer%2Fcode%2Fsuccess.php – wooncherk 2012-07-08 15:58:03

相關問題