因此,我目前在闲暇时间玩弄android编程,并且我将android studio用作我的选择。我目前正在尝试使用youtube api制作一个非常简单的应用。我的问题是我无法弄清楚如何将api真正放入我的应用程序中。我已经使用file> project结构将东西添加到我的应用程序中,但是它本身无法正常工作。它不再对语法错误对我大吼大叫,但在编译时却出现了错误。

我对此进行了一些研究,发现我需要添加一些内容到build.gradle或settings.gradle(或两者)中,但是我还没有找到确切的答案。到目前为止,我尝试过的所有方法都没有奏效。所以,如果有人可以向我解释我该怎么做,或者将我链接到一个可以解释我该怎么做的地方,那将是很好的

- 编辑 -

我现在很困惑。我开始了一个新项目。我添加了库,它仍然可以编译。然后,我添加了导入,并引发了错误。然后我将它们添加到build.gradle中,它能够完美地编译

compile fileTree(dir: 'libs/youtube', include: '*.jar')
compile fileTree(dir: 'libs/youtube/libs', include: '*.jar')

但是当我添加需要库的代码时
/** Global instance of the HTTP transport. */
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();

/** Global instance of the JSON factory. */
private static final JsonFactory JSON_FACTORY = new JacksonFactory();

/** Global instance of Youtube object to make all API requests. */
private static YouTube youtube;

语法不错,但是编译时抛出了错误
 Gradle: Execution failed for task ':Apitest:dexDebug'.
> Failed to run command:

然后是大约100行文件位置

关于我在做什么错的任何想法吗?

最佳答案

只需在gradle文件中添加此依赖项即可:

compile 'com.google.apis:google-api-services-youtube:v3-rev181-1.22.0'

并使用YouTube对象。

引用:
https://developers.google.com/api-client-library/java/apis/youtube/v3

10-07 19:31
查看更多