Announcement Announcement Module
Collapse
No announcement yet.
Spring Social Web - Activity object without content when Accessing with OAuth2 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Social Web - Activity object without content when Accessing with OAuth2

    Hi everyone.

    I'm trying to use spring-social-google to search activities in google+, but when i get the activity objects they came with the Content property set to null. Is this a permission problem?

    I use OAuth2 to get the permissions. The code is like this:

    Code:
    OAuth2Operations oauthOperations = googleConnectionFactory.getOAuthOperations();
        OAuth2Parameters params = new OAuth2Parameters();
        params.setRedirectUri(applicationUrl + GOOGLE_REDIRECT_URI);
        params.setScope("https://www.googleapis.com/auth/plus.me https://www.google.com/m8/feeds/ https://www.googleapis.com/auth/userinfo.email  https://www.googleapis.com/auth/userinfo.profile");
        params.set("access_type", "offline");
        params.set("approval_prompt","force");
        
        String authorizeUrl = oauthOperations.buildAuthorizeUrl( GrantType.AUTHORIZATION_CODE, params );
    I get the Access token and Refresh token with no problem, then i made the search with:

    Code:
    		List<Publication> activities = new ArrayList<Publication>();
    		ActivityQueryBuilder searchResult = google.activityOperations().activityQuery();
    		searchResult.searchFor(query);
    		ActivitiesPage page = searchResult.getPage();
    		List<? extends Activity> activityList = page.getItems();
    		activities.addAll( (List<Publication>) CollectionUtils.collect( activityList, new ActivityToPublicationTransformer() ) );
    The transformer contains this transform method:

    Code:
    public Object transform(Object input) {
    		Publication publication = null;
    		if (input instanceof Activity){
    			User user = new User();
    			Activity activity = (Activity) input;
    			publication = new Publication();
    			publication.setPublicationId(activity.getId());
    			publication.setType( PublicationType.ACTIVITY );
    			publication.setSocialNetwork( SocialNetwork.GOOGLE );
    			user.setName(activity.getActor().getDisplayName());
    			user.setUserId(activity.getActor().getId());
    			publication.setUser(user);
    			publication.setMessage(activity.getContent());
    			publication.setCreatedTime(activity.getPublished());
    			publication.setShares(activity.getResharers());
    			publication.setComments(activity.getReplies());
    			publication.setAttentions( new ArrayList<Attention>() );
    		}
    		return publication;
    	}
    When I debug the application, the instrucction "activity.getContent()" in the transformer returns me null, but activity.getPublished() or activity.getId() works fine.

    Any hint about what am i doing wrong?

    Is there any page with the JavaDoc of spring-social-google? I searched it but i didn't find it

    P.D. Sorry mi bad english, it's not my natural language.
    P.D.2 I just realized I wrote wrong the title, it should begin with "Spring Social Google" not "Spring Social Web", could an admin change the title?
    Last edited by luisfmp; Sep 27th, 2012, 06:17 PM.

  • #2
    First, know that Spring Social Google is a community-contributed project, led by Gabriel Axel. I know very little about it other than how it interacts with Spring Social Core. If Gabriel is listening, perhaps he can help...if not, then I suggest you contact him via a message on GitHub or as an Issue submitted to https://github.com/GabiAxel/spring-social-google.

    With that said, let me attempt to guess my way through this: Is it possible that the specific Activity you received simply does not have a value for content? I don't know if it's possible to have not have a content value for Activity, but I can imagine how it might be. Certainly the ID and created time would be set, as those are assigned by Google when it is created. But if the user who created the activity didn't set the content, then I could see how that may return null.

    If that's the case, then you should probably do a null check on getContent() before attempting to use it.

    Comment


    • #3
      Thanks habuma for your response, I will try to contact Gabriel.

      I think the same the first time a saw the problem, that maybe the activity doesn't have a content but all the "Activity" objects came with this propertie in null, so I think it could be a problem with the scope when I get the Access Token, but I can't figure out where exactly.
      I will still checking.

      Comment


      • #4
        Hello there.

        I check out deeply the google plus publications (I just begin to use te social network), and it seems that Habuma was right, the publications I got from the search were created witouth "content", I create a publication in my google plus account and It had content, then I created a publication from a blog page using the g+ button and the publication was created without "content" (I check the jason response in https://developers.google.com/oauthplayground) but with "attachment", so I think this kind of publication are the type of publications I was getting in my search.

        I decided change my code to set the title in my message content.

        Code:
        publication.setMessage(activity.getTitle());
        Thanks a lot for the responses and reads, sorry if I made waste your time.
        Last edited by luisfmp; Sep 28th, 2012, 01:40 PM.

        Comment


        • #5
          I'm just glad you figured it out. Sometimes I'm good at guessing. :-)

          Comment

          Working...
          X