如何在Google Plus上使用PlusDoamins发布图像



我想在 C# 中将图像/图片发布/上传到 Google+ 流/墙 asp.net 我有很多谷歌,但无法完善任何解决方案,以便我可以将图像从我的应用程序发布到 Google plus 墙。 请帮忙。提前致谢

我无法访问Google+域帐户,因此无法帮助您对此进行测试。 但是,我有一个生成的示例,可能会让您入门

奥特2

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

相关内容

  • 没有找到相关文章

最新更新