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,設置錯誤,不應該使用調試鍵或其他錯誤運行。誰能幫忙?謝謝!