Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to share text and image on my Google plus stream. This text and image would be set by me.

I have do a lot of Research on this i have founded that Google plus API is read only then what did the moment insert do in G+ API ...??

Is there any way if i can sync the text from my Facebook or twitter account. I have make this application in C#.

My Code to add moment is working fine but did'nt understand that where it is adding the moment

C#
private async Task Run()
        {

  UserCredential credential;

            var initializer = new GoogleAuthorizationCodeFlow.Initializer
            {
                ClientSecrets = secrets,
                Scopes = new[] { PlusService.Scope.PlusLogin }                
            };
            var flow = new AAGoogleAuthorizationCodeFlow(initializer);
            credential = await new AuthorizationCodeInstalledApp(flow, new LocalServerCodeReceiver()).AuthorizeAsync
                ("user", CancellationToken.None).ConfigureAwait(false);

            // Create the service.
            var service = new PlusService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "Gus API",
            });

            Moment body = new Moment();
            ItemScope itemScope = new ItemScope();
            itemScope.Id = "**********************";
            itemScope.Image = "http://www.google.com/s2/static/images/GoogleyEyes.png";
            itemScope.Type = "";
            itemScope.Description = "The description for the action";
            itemScope.Name = "An example of add activity";
            body.Target = itemScope;
            body.Type = "http://schema.org/AddAction";
            MomentsResource.InsertRequest insert =
                new MomentsResource.InsertRequest(
                    service,
                    body,
                    "me",
                    MomentsResource.InsertRequest.CollectionEnum.Vault);

            Moment wrote = insert.Execute();
}


public static ClientSecrets secrets = new ClientSecrets()
{
    ClientId = "***********************",
    ClientSecret = "***************"
};


 public class AAGoogleAuthorizationCodeRequestUrl : GoogleAuthorizationCodeRequestUrl
    {
        [Google.Apis.Util.RequestParameterAttribute("request_visible_actions", Google.Apis.Util.RequestParameterType.Query)]
        public string VisibleActions { get; set; }

        public AAGoogleAuthorizationCodeRequestUrl(Uri authorizationServerUrl)
            : base(authorizationServerUrl)
        {
        }
    }

    public class AAGoogleAuthorizationCodeFlow : AuthorizationCodeFlow
    {
        /// <summary>Constructs a new Google authorization code flow.</summary>
        public AAGoogleAuthorizationCodeFlow(AuthorizationCodeFlow.Initializer initializer)
            : base(initializer)
        {
        }

        public override AuthorizationCodeRequestUrl CreateAuthorizationCodeRequest(string redirectUri)
        {
            return new AAGoogleAuthorizationCodeRequestUrl(new Uri(AuthorizationServerUrl))
            {
                ClientId = ClientSecrets.ClientId,
                Scope = string.Join(" ", Scopes),
                RedirectUri = "http://localhost:4567/",
                VisibleActions = "http://schemas.google.com/AddActivity"
            };
        }
    }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900