Как разместить изображения с помощью plusdoamins в Google Plus

Я хочу опубликовать / загрузить изображение / изображение в Google+ поток / стену на C# asp.net. У меня много Google, но я не смог найти ни одного решения, чтобы я мог опубликовать изображение из своего приложения на стене Google plus. пожалуйста помоги. заранее спасибо

1 ответ

У меня нет доступа к учетной записи домена Google+, поэтому я не могу помочь вам проверить это. Однако у меня есть сгенерированный образец, который может помочь вам начать

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;
            }

        }

Загрузка медиа

  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;
            }
         }

    }
Другие вопросы по тегам