要仅使用API密钥验证youtube API请求,请删除 api.client.setApiKey 方法调用。
api.client.setApiKey
在调用YouTube数据API时,为API请求添加一个关键参数:
var request = gapi.client.youtube.search.list({ part: 'snippet', type: 'video', maxResults: 12, q: searchValue, key: 'YourAPIKeyGoesHere' });
这意味着只有这些API调用才被授权,而不是端点调用。
我对Youtube Data API并不是非常熟悉。但我将您用于端点的代码识别为我们提供的代码。您绝对可以将此代码用于Endpoints API。对于Youtube数据,我建议 看这里 。
看起来你需要的代码是这样的:
import com.google.api.client.auth.oauth2.Credential; import com.google.api.services.youtube.YouTube; public class myClass { /** * Define a global instance of a Youtube object, which will be used * to make YouTube Data API requests. */ private static YouTube youtube; public static void main(String[] args) { List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube"); try { // Authorize the request. Credential credential = Auth.authorize(scopes, "invideoprogramming"); // This object is used to make YouTube Data API requests. youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential) .setApplicationName([YOUR APP]) .build(); }
从那里你应该能够使用youtube对象进行调用,并使用gapi将东西发送到你的终端。