The client id, secret etc are correct. I rechecked them. Google + sign in works and I get access token also, but when I try to use YouTube video rating API, it gives 403 forbidden error in real devices. However it works fine in simulator. What can be the issue here? Can anybody help?
P.S. Before I didn't use "gc.setScope("https://www.googleapis.com/auth/youtube.force-ssl")" this line in the code and it gives same forbidden error in simulator as well, but now I added the line and works in simulator, but gives the 403 forbidden error in real devices.
sign.addActionListener((e) -> {
String clientId = "873649282964-7r6088ua0jhoua2tngpblhf4u8elda55.apps.googleusercontent.com";
String redirectURI = "https://www.youtube.com/";
String clientSecret = "_T7cyd-kWQKDzH0ZwiIeq1jr";
gc = GoogleConnect.getInstance();
gc.setClientId(clientId);
gc.setRedirectURI(redirectURI);
gc.setClientSecret(clientSecret);
gc.setScope("https://www.googleapis.com/auth/youtube.force-ssl");
gc.setCallback(new LoginCallback() {
@Override
public void loginFailed(String errorMessage) {
System.out.println("errorMessage");
}
@Override
public void loginSuccessful() {
System.out.println("login success");
}
});
if (!gc.isUserLoggedIn()) {
gc.doLogin();
} else {
//get the token
token = gc.getAccessToken().getToken();
}
});
Button like = new Button("Like");
likeForm.add(like);
like.addActionListener((e) -> {
token = gc.getAccessToken().getToken();
ConnectionRequest cr = new ConnectionRequest() {
@Override
protected void readResponse(InputStream input) throws IOException {
super.readResponse(input);
}
@Override
protected void postResponse() {
like.setText("Like: " + "ok");
}
};
cr.setPost(true);
cr.setUrl("https://www.googleapis.com/youtube/v3/videos/rate?id=" + "lIHr4ZVMBoo" + "&rating=like&access_token="+ token);
System.out.println("geturl " + cr.getUrl());
cr.setDuplicateSupported(true);
NetworkManager.getInstance().addToQueueAndWait(cr);
});
Error log:
04-15 08:05:10.761: E/GMPM(5344): getGoogleAppId failed with status: 10
04-15 08:05:10.761: E/GMPM(5344): Uploading is not possible. App measurement disabled
04-15 08:06:02.901: E/Volley(2900): [154] BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/plus/v1/people/me