Felipe
Felipe

Reputation: 33

Error in simple insertion (moment) in my google+ page (. Net)

Good Night,

I tried adding the parameters as the comments, however to no avail. I got the following code, however now the error is now ...

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

Can someone help me because I'm almost thinking it is not possible.

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

Upvotes: 1

Views: 625

Answers (1)

Joanna
Joanna

Reputation: 2176

To be able to write an AppActivity, you need to set the request-visible-actions parameter when configuring your Google+ Sign-In button. This parameter indicates which AppActivityTypes you intend to write. You can learn more at https://developers.google.com/+/web/app-activities/?hl=en or by watching this Google+ Developers Live episode: http://www.youtube.com/watch?v=cQC_EanIaUw#t=6m46s.

Upvotes: 2

Related Questions