1
votes

i have just listing down the circle name in my google+domain api but getting an error of

i have used installed application-> other option while making the application in google developer console

I am developing a small installed application wherein I am integrating with Google+ Domain API's. I am using OAuth2 authentication.I have generated client_id and client_secret for my Installed application from Google API console. Using Google+ Domain API's, I am able to generate the access token.

Also I am using [email protected] using gmail account

my code is as :-

enter code here


private static final String CLIENT_ID = "xyxxxxxxxx something in there";
private static final String CLIENT_SECRET = "Fhh1LYQ__UTso48snXHyqSQ2";


public static void main(String[] args) throws IOException {

// List the scopes your app requires:
try{
List<String> SCOPE = Arrays.asList(
    "https://www.googleapis.com/auth/plus.me",
    "https://www.googleapis.com/auth/plus.stream.write",
    "https://www.googleapis.com/auth/plus.circles.read");

final String REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob";


GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
        new NetHttpTransport(),
        new JacksonFactory(),
        CLIENT_ID, // This comes from your Developers Console project
        CLIENT_SECRET, // This, as well
        SCOPE)
        .setApprovalPrompt("force")
        // Set the access type to offline so that the token can be refreshed.
        // By default, the library will automatically refresh tokens when it
        // can, but this can be turned off by setting
        // dfp.api.refreshOAuth2Token=false in your ads.properties file.
        .setAccessType("offline").build();

                       // This command-line se`enter code here`rver-side flow example requires the                user             to open the
    // authentication URL in their browser to complete the process. In most
    // cases, your app will use a browser-based server-side flow and your
    // user will not need to copy and paste the authorization code. In this
    // type of app, you would be able to skip the next 5 lines.
    // You can also look at the client-side and one-time-code flows for other
    // options at https://developers.google.com/+/web/signin/
    String url = flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URI).build();
    System.out.println("Please open the following URL in your browser then " +
        "type the authorization code:");
    System.out.println("  " + url);
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String code = br.readLine();
    // End of command line prompt for the authorization code.

    GoogleTokenResponse tokenResponse = flow.newTokenRequest(code)
        .setRedirectUri(REDIRECT_URI).execute();
    GoogleCredential credential = new GoogleCredential.Builder()
        .setTransport(new NetHttpTransport())
        .setJsonFactory(new JacksonFactory())
        .setClientSecrets(CLIENT_ID, CLIENT_SECRET)
        .addRefreshListener(new CredentialRefreshListener() {
          @Override
          public void onTokenResponse(Credential credential, TokenResponse tokenResponse) {
            // Handle success.
            System.out.println("Credential was refreshed successfully.");
          }

          @Override
          public void onTokenErrorResponse(Credential credential,
              TokenErrorResponse tokenErrorResponse) {
            // Handle error.
            System.err.println("Credential was not refreshed successfully. "
                + "Redirect to error page or login screen.");
          }
        })
        // You can also add a credential store listener to have credentials
        // stored automatically.
        //.addRefreshListener(new CredentialStoreRefreshListener(userId, credentialStore))
        .build();

    // Set authorized credentials.
    credential.setFromTokenResponse(tokenResponse);
    // Though not necessary when first created, you can manually refresh the
    // token, which is needed after 60 minutes.
    credential.refreshToken();

    // Create a new authorized API client
    PlusDomains service = new PlusDomains.Builder(new NetHttpTransport(), new JacksonFactory(), credential).setApplicationName("Get-me").setRootUrl("https://www.googleapis.com/").build();


    PlusDomains.Circles.List listCircles = service.circles().list("me");
    listCircles.setMaxResults(5L);
    CircleFeed circleFeed = listCircles.execute();
    List<Circle> circles = circleFeed.getItems();

    // Loop until no additional pages of results are available.
    while (circles != null) {
      for (Circle circle : circles) {
        System.out.println(circle.getDisplayName());
      }

      // When the next page token is null, there are no additional pages of
      // results. If this is the case, break.
      if (circleFeed.getNextPageToken() != null) {
        // Prepare the next page of results
        listCircles.setPageToken(circleFeed.getNextPageToken());

        // Execute and process the next page request
        circleFeed = listCircles.execute();
        circles = circleFeed.getItems();
      } else {
        circles = null;
      }
    }
             }catch(Exception e)
          {
           System.out.println("Exception  "+e);
           }

           }

Its an INSTAlled Application -> other Options........ in google developer console

i get the below error:---

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

Note: I have also enabled Google+ Domain API in my Google API Console.

REDIRECT_URI ="urn:ietf:wg:oauth:2.0:oob" since it's a Installed app. Any Suggestions?

Please help me out guys

1

1 Answers

2
votes

See this other answer: the Google+ Domains API is only "for people who use Google Apps at college, at work, or at home." It appears that Google does not currently allow apps to list circles for regular Google+ accounts.