2013-04-10 44 views
1

晚安,在我的google +頁面(.Net)中簡單插入(時刻)的錯誤

我嘗試添加參數作爲註釋,但無濟於事。 我得到了下面的代碼,但是現在的錯誤是現在...

ProtocolException as caught 
Error occurred while sending a direct message or getting the response. 

有人可以幫助我,因爲我幾乎以爲這是不可能的。

Public Shared Function PostPlus2(sMsg As String) As Boolean 
     Try 

      Dim sPath_Absolut As String = HttpContext.Current.Server.MapPath("~/funcoes/") 

      Dim ServiceAccountId As String = "****************************.apps.googleusercontent.com" 
      Dim ServiceAccountUser As String = "***************************@developer.gserviceaccount.com" 
      Dim Certificado As String = sPath_Absolut + "Certificado\privatekey.p12" 

      Dim oCertificate As X509Certificate2 = New X509Certificate2(Certificado, "notasecret", X509KeyStorageFlags.Exportable) 'Or X509KeyStorageFlags.MachineKeySet 

      'Dim GooAuthServer As DotNetOpenAuth.OAuth2.AuthorizationServerDescription = GoogleAuthenticationServer.Description 
      'GooAuthServer.AuthorizationEndpoint = New Uri(GooAuthServer.AuthorizationEndpoint.AbsoluteUri + "?" + "request_visible_actions=http://schemas.google.com/AddActivity" + "&" + "access_type=offline") 
      'Dim oClient As New AssertionFlowClient(GooAuthServer, oCertificate) With 

      Dim oClient As New AssertionFlowClient(GoogleAuthenticationServer.Description, oCertificate) With 
      { 
      .ServiceAccountId = ServiceAccountUser, 
      .ServiceAccountUser = "************@gmail.com", 
      .Scope = Plus.v1.PlusService.Scopes.PlusMe.GetStringValue() 
           } 


      Dim oAuth As New OAuth2Authenticator(Of AssertionFlowClient)(oClient, AddressOf AssertionFlowClient.GetState) 
      Dim oInitializer As New BaseClientService.Initializer() With 
      { 
      .Authenticator = oAuth 
      } 

      Dim oPlusServ As New Plus.v1.PlusService(oInitializer) 

      Dim body As New Plus.v1.Data.Moment() 
      Dim target As New Plus.v1.Data.ItemScope() 
      target.Id = "4" 
      target.Image = "http://www.google.com/s2/static/images/GoogleyEyes.png" 
      target.Type = "http://schemas.google.com/AddActivity" 
      target.Description = "teste description" 
      target.Name = "teste name" 
      target.Url = "https://developers.google.com/+/web/snippet/examples/thing" 

      body.Target = target 
      body.Type = "http://schemas.google.com/AddActivity" 

      Dim insert As New Plus.v1.MomentsResource.InsertRequest(
        oPlusServ, 
        body, 
        "me", 
        Plus.v1.MomentsResource.Collection.Vault) 

      insert.Fetch() 
      'Dim wrote As Plus.v1.Data.Moment = insert.Fetch() 

      Return True 
     Catch ex As Exception 
      Return False 
     End Try 
    End Function 
+0

+1不會忘記隱藏真實的登錄數據 – Amegon 2013-04-10 00:19:56

回答

2

要編寫AppActivity,需要在配置Google+登錄按鈕時設置request-visible-actions參數。此參數指示您打算編寫哪個AppActivityType。您可以通過https://developers.google.com/+/web/app-activities/?hl=en或通過觀看Google+開發人員現場節目http://www.youtube.com/watch?v=cQC_EanIaUw#t=6m46s瞭解更多信息。

+0

早上好,感謝您的關注。 我想在我自己的網頁上發佈google +,我只是,所以我使用的是「谷歌帳戶」,因爲我不會向用戶索要密鑰。 但是我給出的下面的鏈接在VB.net或C#中沒有例子,而是直接使用OAuth,您必須指定request_visible_actions。我如何? – Felipe 2013-04-10 09:15:40

+0

您是否嘗試通過發送HTTP請求來檢索訪問令牌,然後發佈另一個HTTP請求? 然後,您可以圍繞這些HTTP請求編寫代碼,以使其更易於使用。我在Java中做了同樣的事情,寫了一個GoogleProfile類,它下面使用OAuth2令牌發送HTTP請求 – 2013-04-10 10:55:29

+0

這裏的堆棧溢出問題 - http://stackoverflow.com/questions/15263378/google-insert-moment-using-google- api-dotnet-client/15285699#15285699 - 顯示如何使用傳統的OAuth2流設置request_visible_actions,幷包括使用.NET來執行此操作的C#代碼。您可能想嘗試在Github上使用C#快速入門來完成此操作 - https://github.com/googleplus/gplus-quickstart-csharp – class 2013-04-10 17:43:50