无法直接使用Google OAuth授权

时间:2019-01-04 14:14:49

标签: java youtube google-oauth youtube-data-api

我想直接使用Java代码上传YouTube视频。我不想创建一个额外的页面,但是要授权自己使用YouTube Api的频道。

这是我尝试过的:

GoogleCredential credential = new GoogleCredential.Builder()
    .setTransport(HTTP_TRANSPORT)
    .setJsonFactory(JSON_FACTORY)
    .setClientSecrets("<clientid>", "<clientsecret>")
    .setClock(new Clock() {
        @Override
        public long currentTimeMillis() {
            return System.currentTimeMillis();
        }
    })
    .setTokenServerUrl(new GenericUrl("https://developers.google.com/oauthplayground"))
    .build();
System.out.println(credential.getAccessToken());
youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName("youtube_bot").build();

这不会给我任何例外,但是当我尝试使用

上传视频时
Video returnedVideo = videoInsert.execute(); //like google does it on their doc

我明白了

com.google.api.client.googleapis.json.GoogleJsonResponseException:401未经授权

没有一种使用客户端密钥,id或smth直接授权的方法吗?

0 个答案:

没有答案