Java – re: YouTube video rating API (V3) works in the simulator, but 403 errors occur in real devices
The client ID and password are correct I rechecked them Google login work, I also get access token, but when I try to use YouTube video rating API, it provides 403 Forbidden errors in real devices But it works well in the simulator What could be the problem? Can I help you? Any help is appreciated thank you
Note: I didn't use "GC. Setscope()" before https://www.googleapis.com/auth/youtube.force-ssl This line in the ")" code also gives the same prohibited error in the simulator, but now I have added this line and worked in the simulator, but in practice, it gives 403 prohibited error 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
Solution
You print login errors or successes to the console instead of displaying the UI that will be visible on the device Therefore, your login may not succeed
As far as I know, the Google API also needs to authorize the HTTP header because we use it here, but if it works on the simulator, I'm not sure what the problem is