2012-01-31 121 views
0

有沒有人用過google-gdata的「新DocumentsList API」?新的Google DocumentsList API .NET客戶端?

我想檢索一個文件列表,我遇到了驗證問題。

使用Google.GData.Documents類工作正常,但是當我嘗試以類似的方式使用,然後更新Google.GData.Docs我得到一個401

如果有幫助,我已經注意到,我的電子郵件地址不會附加到網址中,就像我使用Google.GData.Documents時一樣。

任何人都可以幫忙嗎?

感謝

代碼的要求:

[Authorize] 
public void ListAsync() 
{ 
    string requestorId = ""; 
    if (Session["email"] != null) 
    { 
     // get a documents list for the user that logged in 
     requestorId = Session["email"].ToString(); 
    } 

    // create an OAuth factory to use 
    GOAuthRequestFactory requestFactory = new GOAuthRequestFactory("writely", APPLICATION_NAME); 
    requestFactory.ConsumerKey = "XXX"; 
    requestFactory.ConsumerSecret = "YYY"; 

    DocsService service = new DocsService(APPLICATION_NAME); 

    // this way does work 
    //service.setUserCredentials("username", "password"); 

    // this way doesn't work 
    service.RequestFactory = requestFactory; 

    Uri queryUri = new Uri("https://docs.google.com/feeds/default/private/full"); 

    service.AsyncOperationCompleted += DocsQueryCompleted; 
    AsyncManager.OutstandingOperations.Increment(); 
    service.QueryFeedAync(queryUri, DateTime.MinValue, this); 
} 
+0

發佈您的代碼。刪除所有私人信息並在其位置使用示例值。一旦你有問題的代碼,我會扭轉我的downvote。 – 2012-01-31 13:14:15

回答

0
 OAuth2Parameters parameters = new OAuth2Parameters();    
     parameters.ClientId = CLIENT_ID; 
     parameters.ClientSecret = CLIENT_SECRET; 
     parameters.RedirectUri = REDIRECT_URI; 
     parameters.Scope = SCOPE; 
     string authorizationUrl = OAuthUtil.CreateOAuth2AuthorizationUrl(parameters); 

試圖獲得與authorizationUrl身份驗證令牌。將其粘貼到網絡瀏覽器中。然後... 使用令牌作爲strToken那樣。您現在擁有所有的信息。

 OAuth2Parameters parameters = new OAuth2Parameters();    
     parameters.ClientId = CLIENT_ID; 
     parameters.ClientSecret = CLIENT_SECRET; 
     parameters.RedirectUri = REDIRECT_URI; 
     parameters.Scope = SCOPE; 
     parameters.AccessToken= accessToken; 
     parameters.RefreshToken= refreshToken; 

     GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "MyDocumentsListIntegration-v1", parameters); 
     Serv = new DocumentsService("MyDocumentsListIntegration-v1"); 
     Serv.RequestFactory = requestFactory; 

此代碼必須工作。