0
Public Function GooglePlusPostNow(ByVal _PostContent As String, ByVal _PostName As String, ByVal _StartDate As String, ByVal _LinkedBackURL As String) As Boolean
            Dim clientID As String = "ClientID.apps.googleusercontent.com"
            Dim body As New Moment
            Dim target As New ItemScope
            target.Id = "1"
            target.Image = "Image"
            target.Type = "http://schemas.google.com/AddActivity"
            target.Description = _PostContent
            target.Url = _LinkedBackURL
            target.Name = _PostName
            body.Target = target
            body.Type = "http://schemas.google.com/AddActivity"
            Dim insert As New MomentsResource.InsertRequest(PlusService(), body, clientID, MomentsResource.Collection.Vault)
            Dim wrote As Moment = insert.Fetch()

End Function


Private Function BuildAuth() As BaseClientService.Initializer
    Dim Service_Account_Email As String = "yourserviceaccount@developer.gserviceaccount.com"
    Dim Service_Account_PKCS12_File_Path As String = "Certificate Path"
    Dim certificate As X509Certificate2 = New X509Certificate2(Service_Account_PKCS12_File_Path, "notasecret", X509KeyStorageFlags.Exportable)
    Dim GoogleAuthServer As DotNetOpenAuth.OAuth2.AuthorizationServerDescription = GoogleAuthenticationServer.Description
    GoogleAuthServer.AuthorizationEndpoint = New Uri(GoogleAuthServer.AuthorizationEndpoint.AbsoluteUri + "?" + "data-requestvisibleactions=AddActivity" + "&" +        "access_type=offline")
    Dim provider As New Authentication.OAuth2.DotNetOpenAuth.AssertionFlowClient(GoogleAuthServer, certificate) With {.ServiceAccountId = Service_Account_Email, .Scope =       Plus.v1.PlusService.Scopes.PlusLogin.GetStringValue()}
    Dim auth As New OAuth2Authenticator(Of Authentication.OAuth2.DotNetOpenAuth.AssertionFlowClient)(provider, AddressOf Authentication.OAuth2.DotNetOpenAuth.AssertionFlowClient.GetState)
    Dim init As New Google.Apis.Services.BaseClientService.Initializer
    init.ApiKey = "API Key"
    init.Authenticator = auth
    Return init
End Function

Private Function PlusService() As PlusService
            Dim ps As New PlusService(BuildAuth)
            Return ps
End Function
4

0 回答 0