将 YouTube 数据 API 添加到 Android Studio [英] Add YouTube Data API to Android Studio

查看:46
本文介绍了将 YouTube 数据 API 添加到 Android Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我目前在空闲时间忙于 android 编程,我使用 android studio 作为我的首选.我目前正在尝试使用 youtube api 制作一个非常简单的应用程序.我的问题是我无法弄清楚如何将 api 实际放入我的应用程序中.我已经使用文件> 项目结构将这些内容添加到我的应用程序中,但这本身并不起作用.它停止对我大喊语法错误,但是当它编译错误时.

So, I am currently messing around with android programming in my free time, and I am using android studio as my ide of choice. I am currently trying to make a very simple app using the youtube api. My issue is that I cant figure out how to actually get the api into my application. I have used file>project structure to add the stuff to my application, but that doesnt work by itself. It stops yelling at me about syntax errors but when it compiles it errors.

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

I researched this a bit and have found that I need to add stuff to build.gradle or settings.gradle(or both) but i havent found a definitive answer on exactly what to do. Everything I have tried thus far hasnt worked. SO if someone could either explain to me what i have to do, or link me to a place where it explains what to do that would be great

--编辑--

我现在很困惑.我开始了一个新项目.我添加了库,它仍然能够编译.然后我添加了导入,它抛出了关于它的错误.然后我将这些添加到 build.gradle 中,它能够完美编译

I am so confused right now. I started a new project. I added the libs and it was still able to compile. I then added the imports and it threw errors about it. I then added these to the build.gradle and it was able to compile perfectly

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

但是当我添加这个需要库的代码时

But when i added this code that requires the library

/** 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;

语法没问题,但编译时报错

the syntax was fine but it threw an error upon compiling it

 Gradle: Execution failed for task ':Apitest:dexDebug'.
> Failed to run command:

然后是大约 100 行的文件位置

and that was followed by about 100 lines of of file locations

对我做错了什么有任何想法吗?

Any ideas as to what i am doing wrong?

推荐答案

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

Just add this dependency in gradle file:

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

并使用 YouTube 对象.

and use YouTube object.

参考:https://developers.google.com/api-client-library/java/apis/youtube/v3

这篇关于将 YouTube 数据 API 添加到 Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆