I have a Java application that uses the Google Contact API to sync contacts with a a local PDA application. It was working fine on my old machine, but after copying the source and everything (including client_secrets.json) to a new laptop, I now get the following error calling com.google.gdata.client.Service.getFeed():
com.google.gdata.util.ServiceForbiddenException: Cannot request contacts belonging to another user
I am passing in the same user ID and password as before, so I'm not sure why it says "another user".
Here's my relevant code:
// Initialize Contacts service
service = new ContactsService(cfg.gAppName);
// Authorize the service
Credential credential = authorize(CONTACTS_SCOPE, "contacts");
if (credential != null && (credential.getExpiresInSeconds() == null || credential.getExpiresInSeconds() < 5)) {
credential.refreshToken();
}
String token = credential.getAccessToken();
service.setHeader("Authorization", "Bearer " + token);
// Request the feed
contFeedUrl = new URL(BASE_CONT_URL + CONTACTS + cfg.gUser + "/full?max-results=999999");
if (bFeed) {
resultFeed = service.getFeed(contFeedUrl, ContactFeed.class);
}
And this is my authorize() method:
protected Credential authorize(String scope, String subDir) throws Exception {
File dataStoreDir = new File(System.getProperty("user.home"), ".store/gsync/" + cfg.dataStore + "/" + subDir);
// initialize the transport
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
// initialize the data store factory
dataStoreFactory = new FileDataStoreFactory(dataStoreDir);
// load client secrets
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
new InputStreamReader(SyncMgr.class.getResourceAsStream("/client_secrets.json")));
if (clientSecrets.getDetails().getClientId().startsWith("Enter")
|| clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
System.out.println(
"Enter Client ID and Secret from https://code.google.com/apis/console/?api=calendar "
+ "into /client_secrets.json");
System.exit(1);
}
// set up authorization code flow
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, JSON_FACTORY, clientSecrets,
Collections.singleton(scope)).setDataStoreFactory(dataStoreFactory).build();
// authorize
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize(cfg.gUser);
}
Any ideas how I can get it working on the new machine?