2
我想在Android应用检索YouTube频道,并具有下面的代码:如何在Youtube的Android API中将API密钥放入Youtube.Builder中?
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new GsonFactory();
GoogleCredential credential = new GoogleCredential()
.setAccessToken("<my api key>");
YouTube yt = new YouTube.Builder(transport, jsonFactory,
credential).build();
try {
List l = yt.channels().list("id");
l.put("id", "UCO3bfz4KY6zGT5IOaFJuxpA");
ChannelListResponse resp = l.execute();
java.util.List<Channel> chs = resp.getItems();
for (Channel ch : chs) {
// ...
}
} catch (IOException e1) {
e1.printStackTrace();
}
但我得到的错误响应消息"Invalid Credentials"
。我正在使用https://console.developers.google.com/project/<project name>/apiui/credential
中的API密钥,分段为Public API access
,API KEY
。
我不知道我使用了错误的键,错误的API,设置错误,不应该使用调试键或其他错误运行。谁能帮忙?谢谢!