Trần Đức Anh
Trần Đức Anh

Reputation: 127

Get the Post Of User On Google Plus

I got a problem on getting the post of user on google plus. I only have the access token and refresh token of this user ( not the ID !), how could i get the post from google plus of this user ?, i do searching a lot, but none of them meets my circumstance. When the user provide his google plus Id on the front end side, the access token and refresh token were generated and stored in database, i, on the backend side, will use these tokens to retrieve the post of this user. p/s: I use this library https://code.google.com/p/google-plus-java-api/ because it looks so simple, i don't want to use so complicated library just for getting the post, thanks you guy a lot

here is my code

    import com.googlecode.googleplus.GooglePlusFactory;
    import com.googlecode.googleplus.Plus;
    import com.googlecode.googleplus.model.activity.ActivityCollection;
    import com.googlecode.googleplus.model.activity.ActivityFeed;

    public void getInfo(String accessToken, String refreshToken) {
    
    GooglePlusFactory factory = new GooglePlusFactory(clientId, clientSecret);
    Plus plus = factory.getApi(accessToken, refreshToken,null);
    if (plus != null) {
        ActivityFeed af = plus.getActivityOperations().list("me",ActivityCollection.PUBLIC);
        String firstpost = af.getItems().get(0).getObject().getContent();
     } 

, i got 403 error when call this method, the error output was :

 403 Forbidden 
 { 
   "code" : 403, 
    "errors" : [ { 
   "domain" : "usageLimits", 
   "message" : "Daily Limit Exceeded. Please sign up", 
   "reason" : "dailyLimitExceededUnreg", 
   "extendedHelp" : "https://code.google.com/apis/console" 
  } ], 
  "message" : "Daily Limit Exceeded. Please sign up" 
 } 

Actually, i think the reason is not because daily limit exceeded, because i got that message at the first time i run, i also turn the google+ api, google+ domain api on google api console. I suppose the error come from using the "me" in the "list" method to retrieve the post. I still dont' have any idea how to fix this problem

Updated #1#:

I have change my code a lot, so here is exactly what i stuck at, i already get a new accessToken, and (when it is still not expired) , i run this code below:

        GoogleCredential credential = new GoogleCredential.Builder()
       .setJsonFactory(JSON_FACTORY)
       .setTransport(TRANSPORT)
       .setClientSecrets(CLIENT_ID, CLIENT_SECRET).build().setAccessToken(newAccessToken);


        // Create a new authorized API client.
        Plus service = new Plus.Builder(TRANSPORT, JSON_FACTORY, credential)
            .setApplicationName(APPLICATION_NAME)
            .build();
        // Get a list of people that this user has shared with this app.
        ActivityFeed feed = service.activities().list("me", "public").execute()

then i got this error:

         com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
         {
           "code" : 403,
            "errors" : [ {
           "domain" : "global",
           "message" : "Insufficient Permission",
           "reason" : "insufficientPermissions"
         } ],
          "message" : "Insufficient Permission"
         }

Upvotes: 1

Views: 1241

Answers (2)

Trần Đức Anh
Trần Đức Anh

Reputation: 127

I solved this problem, everything is fine except 1 thing, that's is the access token and refresh token was created by some scopes but not the scopes Plus.me, that why's i can't request a new access token by using this refresh token, and then i got the insufficient permission error 403. So when i get the new access and refresh token by using the approriated scope, i can query with keyword "me". Hope you guy don't stuck like me, it takes me nearly 2 days to figure it out

Upvotes: 1

Prisoner
Prisoner

Reputation: 50701

Using "me" as the ID for the list call should work correctly, and your code generally appears correct.

The error message suggests that your client is unregistered. I would check to make sure of the following:

Make sure you have created a Client ID and Secret (and don't post them here!) for your project and you're passing them to the GooglePlusFactory correctly.

Authorized API Access

Make sure this project has the Google+ API turned on.

Google+ API

Make sure that the access token you're providing for the user corresponds to them authenticating to this same project

Upvotes: 2

Related Questions