无法解析方法getYouTubeService()

时间:2018-08-12 19:08:29

标签: java android youtube-api

我已经导入了正确的gradle项目...并且我可以使用“ Youtube”对象,但是无法访问其own API docs?中描述的方法

enter image description here

  

无法解析方法getYouTubeService()

  YouTube youtube = getYouTubeService();
        try {
            HashMap<String, String> parameters = new HashMap<>();
            //example
            parameters.put("id", "theid");

            YouTube.Subscriptions.Delete subscriptionsDeleteRequest = youtube.subscriptions().delete(parameters.get("id").toString());
            subscriptionsDeleteRequest.execute();
        }catch(Exception e){
            e.printStackTrace();
        }

成绩:

//youtube api
implementation 'com.google.apis:google-api-services-youtube:v3-rev205-1.24.1'
// Dependency for Google Sign-In
implementation 'com.google.android.gms:play-services-auth:15.0.1'

// Dependencies for the REST API example
implementation 'com.google.api-client:google-api-client:1.22.0'
implementation 'com.google.api-client:google-api-client-android:1.22.0'
implementation 'com.google.apis:google-api-services-people:v1-rev139-1.22.0'

1 个答案:

答案 0 :(得分:0)

您需要与Credentials结合使用,以获取YouTube实例:

new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
                .setApplicationName(APPLICATION_NAME)
                .build();

参考:https://github.com/youtube/api-samples/blob/master/java/src/main/java/com/google/api/services/samples/youtube/cmdline/data/Quickstart.java