-2

I want to post/upload an image/picture to Google+ stream/wall in C# asp.net I have Google a lot but could not fine any solution so that i could post an image from my application to Google plus wall. please help. Thanks in advance

SrB
  • 1
  • 1
  • Welcome to stack please read http://stackoverflow.com/help/how-to-ask. Google does not allow us to programmatically post to Google+ wall that is probably why you where not able to find out how to do it. – Linda Lawton - DaImTo Feb 15 '16 at 09:55
  • Thanks for your reply, but I have read that, https://developers.google.com/+/domains/posts/attaching-media using these domain apis, user can post it, but I am not able to find that ho we can use these :( – SrB Feb 15 '16 at 10:12
  • Google+ domain is not the same as Google+ for normal users. if you are a Google Apps customer then you should contact them to get access this API is not public to my knowledge. You have to have special permission to use it. – Linda Lawton - DaImTo Feb 15 '16 at 10:20
  • There is a nugget package for it. https://www.nuget.org/packages/Google.Apis.PlusDomains.v1/ – Linda Lawton - DaImTo Feb 15 '16 at 10:23
  • We have added these to our asp.net project, but not getting how to use it to authentication and authorization of user and then upload the image. – SrB Feb 15 '16 at 10:25

1 Answers1

0

I don't have access to a Google+ domain account so cant help you test this. However I have a generated sample that might get you started

Oauth2

  /// <summary>
        /// Authenticate to Google Using Oauth2
        /// Documentation https://developers.google.com/accounts/docs/OAuth2
        /// </summary>
        /// <param name="clientId">From Google Developer console https://console.developers.google.com</param>
        /// <param name="clientSecret">From Google Developer console https://console.developers.google.com</param>
        /// <param name="userName">The user to authorize.</param>
        /// <returns>a valid PlusDomainsService</returns>
        public static PlusDomainsService AuthenticateOauth(string clientId, string clientSecret, string userName)
        {
            if (string.IsNullOrEmpty(clientId))
                throw new Exception("clientId is required.");
            if (string.IsNullOrEmpty(clientSecret))
                throw new Exception("clientSecret is required.");
            if (string.IsNullOrEmpty(userName))
                throw new Exception("userName is required for datastore.");


            string[] scopes = new string[] { PlusDomainsService.Scope.PlusCirclesRead,     // View your circles and the people and pages in them
                                             PlusDomainsService.Scope.PlusCirclesWrite,    // Manage your circles and add people and pages. People and pages you add to your circles will be notified. Others may see this information publicly. People you add to circles can use Hangouts with you.
                                             PlusDomainsService.Scope.PlusLogin,           // Know your basic profile info and list of people in your circles.
                                             PlusDomainsService.Scope.PlusMe,              // Know who you are on Google
                                             PlusDomainsService.Scope.PlusMediaUpload,     // Send your photos and videos to Google+
                                             PlusDomainsService.Scope.PlusProfilesRead,    // View your own Google+ profile and profiles visible to you
                                             PlusDomainsService.Scope.PlusStreamRead,      // View your Google+ posts, comments, and stream
                                             PlusDomainsService.Scope.PlusStreamWrite,     // Manage your Google+ posts, comments, and stream
                                             PlusDomainsService.Scope.UserinfoEmail,       // View your email address
                                             PlusDomainsService.Scope.UserinfoProfile};    // View your basic profile info

            try
            {

                string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials/PlusDomains");

                // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
                UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
                                                                                             , scopes
                                                                                             , userName
                                                                                             , CancellationToken.None
                                                                                             , new FileDataStore(credPath, true)).Result;

                var service = new PlusDomainsService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "PlusDomains Authentication Sample",
                });
                return service;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
                throw ex;
            }

        }

Media upload

  class MediaSample
    {
        /// <summary>
        /// Add a new media item to an album. The current upload size limitations are 36MB for a photo and 1GB for a video. Uploads do not count against quota if photos are less than 2048 pixels on their longest side or videos are less than 15 minutes in length.
        /// Documentation: https://developers.google.com/+/domains//v1/media/insert
        /// </summary>
        /// <param name="service">Valid authentcated PlusDomainsService</param>
        /// <param name="body">Valid Media Body</param>
        /// <param name="userId">The ID of the user to create the activity on behalf of.</param>
        /// <param name="collection"> Upload the media to share on Google+.</param>
        /// <returns>Media </returns>
        public static Media Insert(PlusDomainsService service, Media body, string userId, MediaResource.InsertRequest.CollectionEnum collection)
        {
            //Note Genrate Argument Exception (https://msdn.microsoft.com/en-us/library/system.argumentexception(loband).aspx)
            try
            {  
            return          service.Media.Insert(body, userId, collection).Execute();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Request Failed " + ex.Message);
                throw ex;
            }
         }

    }
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Make sure you enabled the Google+ Domains API in the Google Developers console not the Google+ API. – Linda Lawton - DaImTo Feb 15 '16 at 10:52
  • You may also have to grant the user access to use it in the https://apps.google.com/ account. The documentation isn't clear on this. Again I don't have a Google apps account so I cant play with it. – Linda Lawton - DaImTo Feb 15 '16 at 10:59
  • I Tried, but when it goes for this UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { First it get random redirect url, and second it again redirect to the same page, and again goes for that Auth process – SrB Feb 15 '16 at 11:39
  • redirect uri must be set correctly in google developers console. try http://localhost/authorize/ really wish I could help test it all I get is forbidden since I don't have an apps account and haven't been granted access to this API. How did you get access anyway? – Linda Lawton - DaImTo Feb 15 '16 at 11:46
  • noting much :(, retype the own ip address in the error screen when it prompts that redirect uri is not valid, :) but after that it again redirects on that redirect url where we have written that code, how we can check that once user has been auth? – SrB Feb 15 '16 at 11:53
  • redirect URI that you are sending from must be the same as the one you set in the Google developers console. – Linda Lawton - DaImTo Feb 15 '16 at 11:58
  • yeah thats fine, but the application running on http://localhost:56603/gapi.aspx but when it internally calls that authentication url it automatically replaing it with random '&redirect_uri=http://localhost:58528/authorize/' or '&redirect_uri=http://localhost:58323/authorize/' '&redirect_uri=http://localhost:58541/authorize/' – SrB Feb 15 '16 at 11:59
  • did you put localhost:56603/gapi.aspx or localhost/gapi.aspx in google developers console? – Linda Lawton - DaImTo Feb 15 '16 at 12:00
  • localhost:56603/gapi.aspx – SrB Feb 15 '16 at 12:06
  • http://localhost/googleApiDomain/gapi.aspx, and when i tried using this, it enters to never ending process, – SrB Feb 15 '16 at 12:08