/// <summary>
        /// Writes a Google+ App Activity to Google logging that the user has voted on a PhotoHunt
        /// photo.
        /// </summary>
        /// <param name="user">The user who has voted.</param>
        /// <param name="voteTarget">The photo the user has voted on.</param>
        public void WriteGooglePlusVoteAppActivity(User user, Photo voteTarget)
        {
            // Write an app activity for the vote.
            // Set the auth state in a the superclass for the authorization call.
            _authState = CreateState(user.googleAccessToken, user.googleRefreshToken,
                                     user.googleExpiresAt.AddSeconds(user.googleExpiresIn * -1), user.googleExpiresAt);

            AuthorizationServerDescription description =
                GoogleAuthenticationServer.Description;
            var provider = new WebServerClient(description);

            provider.ClientIdentifier = CLIENT_ID;
            provider.ClientSecret     = CLIENT_SECRET;
            var authenticator =
                new OAuth2Authenticator <WebServerClient>(
                    provider,
                    GetAuthorization)
            {
                NoCaching = true
            };

            ps = new PlusService(new BaseClientService.Initializer()
            {
                Authenticator = authenticator
            });

            Moment    body   = new Moment();
            ItemScope target = new ItemScope();
            ItemScope result = new ItemScope();

            // The target (an image) will be parsed from this URL containing microdata.
            target.Url = BASE_URL + "photo.aspx?photoId=" + voteTarget.id;

            // Just use a static review result.
            result.Type = SCHEMA_REVIEW_TYPE;
            result.Name = "A vote for this PhotoHunt photo.";
            result.Url  = target.Url;
            result.Text = "This photo embodies " + voteTarget.themeDisplayName;

            body.Target = target;
            body.Result = result;
            body.Type   = REVIEW_ACTIVITY_TYPE;
            MomentsResource.InsertRequest insert =
                new MomentsResource.InsertRequest(
                    ps,
                    body,
                    "me",
                    MomentsResource.Collection.Vault);
            try
            {
                insert.Fetch();
            }
            catch (GoogleApiRequestException gare)
            {
                Debug.WriteLine("Error while writing app activity: " + gare.InnerException.Message +
                                "\nThis could happen if the Google+ proxy can't access your server.");
            }
        }
        /// <summary>
        /// Write an app activity to Google using the Google+ API logging that the user
        /// has uploaded a Photo.
        /// </summary>
        /// <param name="user">The PhotoHunt user who uploaded the Photo.</param>
        /// <param name="dbPhoto">The Photo that was just uploaded.</param>
        public void WriteGooglePlusPhotoAppActivity(User user, Photo dbPhoto)
        {
            _authState = CreateState(user.googleAccessToken, user.googleRefreshToken,
                                     user.googleExpiresAt.AddSeconds(user.googleExpiresIn * -1), user.googleExpiresAt);

            AuthorizationServerDescription description = GoogleAuthenticationServer.Description;
            var provider = new WebServerClient(description);

            provider.ClientIdentifier = CLIENT_ID;
            provider.ClientSecret     = CLIENT_SECRET;
            var authenticator =
                new OAuth2Authenticator <WebServerClient>(
                    provider,
                    GetAuthorization)
            {
                NoCaching = true
            };

            ps = new PlusService(new BaseClientService.Initializer()
            {
                Authenticator = authenticator
            });

            Moment    body   = new Moment();
            ItemScope target = new ItemScope();

            target.Url = BASE_URL + "photo.aspx?photoId=" + dbPhoto.id;

            body.Target = target;
            body.Type   = ADD_ACTIVITY_TYPE;

            MomentsResource.InsertRequest insert =
                new MomentsResource.InsertRequest(ps, body, "me", MomentsResource.Collection.Vault);
            try
            {
                insert.Fetch();
            }
            catch (GoogleApiRequestException gare)
            {
                Debug.WriteLine("Error while writing app activity: " + gare.InnerException.Message +
                                "\nThis could happen if the Google+ proxy can't access your server.");
            }
        }
Exemplo n.º 3
0
        public Moment WriteDemoMoment()
        {
            Moment body = new Moment();
            ItemScope target = new ItemScope();

            target.Id = "replacewithuniqueforaddtarget";
            target.Image = "http://www.google.com/s2/static/images/GoogleyEyes.png";
            target.Type = "";
            target.Description = "The description for the activity";
            target.Name = "An example of add activity";

            body.Target = target;
            body.Type = "http://schemas.google.com/AddActivity";

            MomentsResource.InsertRequest insert =
                new MomentsResource.InsertRequest(
                    plusService,
                    body,
                    "me",
                    MomentsResource.Collection.Vault);
            Moment m = insert.Fetch();
            return m;
        }
        /// <summary>
        /// Writes a Google+ App Activity to Google logging that the user has voted on a PhotoHunt
        /// photo.
        /// </summary>
        /// <param name="user">The user who has voted.</param>
        /// <param name="voteTarget">The photo the user has voted on.</param>
        public void WriteGooglePlusVoteAppActivity(User user, Photo voteTarget)
        {
            // Write an app activity for the vote.
            // Set the auth state in a the superclass for the authorization call.
            _authState = CreateState(user.googleAccessToken, user.googleRefreshToken,
                user.googleExpiresAt.AddSeconds(user.googleExpiresIn * -1), user.googleExpiresAt);

            AuthorizationServerDescription description =
                GoogleAuthenticationServer.Description;
            var provider = new WebServerClient(description);
            provider.ClientIdentifier = CLIENT_ID;
            provider.ClientSecret = CLIENT_SECRET;
            var authenticator =
                new OAuth2Authenticator<WebServerClient>(
                    provider,
                    GetAuthorization)
                {
                    NoCaching = true
                };
            ps = new PlusService(new BaseClientService.Initializer()
            {
                Authenticator = authenticator
            });

            Moment body = new Moment();
            ItemScope target = new ItemScope();
            ItemScope result = new ItemScope();

            // The target (an image) will be parsed from this URL containing microdata.
            target.Url = BASE_URL + "photo.aspx?photoId=" + voteTarget.id;

            // Just use a static review result.
            result.Type = SCHEMA_REVIEW_TYPE;
            result.Name = "A vote for this PhotoHunt photo.";
            result.Url = target.Url;
            result.Text = "This photo embodies " + voteTarget.themeDisplayName;

            body.Target = target;
            body.Result = result;
            body.Type = REVIEW_ACTIVITY_TYPE;
            MomentsResource.InsertRequest insert =
                new MomentsResource.InsertRequest(
                    ps,
                    body,
                    "me",
                    MomentsResource.Collection.Vault);
            try
            {
                insert.Fetch();
            }
            catch (GoogleApiRequestException gare)
            {
                Debug.WriteLine("Error while writing app activity: " + gare.InnerException.Message +
                    "\nThis could happen if the Google+ proxy can't access your server.");
            }
        }
        /// <summary>
        /// Write an app activity to Google using the Google+ API logging that the user
        /// has uploaded a Photo.
        /// </summary>
        /// <param name="user">The PhotoHunt user who uploaded the Photo.</param>
        /// <param name="dbPhoto">The Photo that was just uploaded.</param>
        public void WriteGooglePlusPhotoAppActivity(User user, Photo dbPhoto)
        {
            _authState = CreateState(user.googleAccessToken, user.googleRefreshToken,
                user.googleExpiresAt.AddSeconds(user.googleExpiresIn * -1), user.googleExpiresAt);

            AuthorizationServerDescription description = GoogleAuthenticationServer.Description;
            var provider = new WebServerClient(description);
            provider.ClientIdentifier = CLIENT_ID;
            provider.ClientSecret = CLIENT_SECRET;
            var authenticator =
                new OAuth2Authenticator<WebServerClient>(
                    provider,
                    GetAuthorization)
                {
                    NoCaching = true
                };
            ps = new PlusService(new BaseClientService.Initializer()
            {
                Authenticator = authenticator
            });

            Moment body = new Moment();
            ItemScope target = new ItemScope();

            target.Url = BASE_URL + "photo.aspx?photoId=" + dbPhoto.id;

            body.Target = target;
            body.Type = ADD_ACTIVITY_TYPE;

            MomentsResource.InsertRequest insert =
                new MomentsResource.InsertRequest(ps, body, "me", MomentsResource.Collection.Vault);
            try
            {
                insert.Fetch();
            }
            catch (GoogleApiRequestException gare)
            {
                Debug.WriteLine("Error while writing app activity: " + gare.InnerException.Message +
                    "\nThis could happen if the Google+ proxy can't access your server.");
            }
        }