4
votes

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
1
According to this document, if the API returns an HTTP 403 response code, then your application may not be registered. Many APIs set a query-volume limit of 0 for unregistered applications and return a 403 response code when the query-volume limit is exceeded. You can check this page that explains how to register your app including the digitally signed .apk file's certificate in the Google Developers Console.KENdi
@KENdi no i did all that. The error log shows "BasicNetwork.performRequest: Unexpected response code 403 for googleapis.com/plus/v1/people/me"beck

1 Answers

0
votes

You print login error or success to the console instead of showing a UI that will be visible on the device. So your login might not be successful.

As far as I recall the Google API's also require the Authorization http header as we used it here but if it worked on the simulator I'm not sure this is the issue.