Android 获取youtube标题失败

Android 获取youtube标题失败,android,youtube-data-api,Android,Youtube Data Api,我想获得Youtube标题和其他内容 我被跟踪了那次描述 以下是我要做的: 我使用改装请求数据 这是我的服务: @GET(“https://www.googleapis.com/youtube/v3/videos?key=“+C.googldavapikey+”&part=snippet、contentDetails、statistics、status”) 调用getYoutubeInfo( @查询(“视频id”)字符串视频id ); 这是您的请求: Api.getClient(上下文) .c

我想获得Youtube标题和其他内容

我被跟踪了那次描述

以下是我要做的: 我使用改装请求数据

这是我的服务:

@GET(“https://www.googleapis.com/youtube/v3/videos?key=“+C.googldavapikey+”&part=snippet、contentDetails、statistics、status”)
调用getYoutubeInfo(
@查询(“视频id”)字符串视频id
);
这是您的请求:

Api.getClient(上下文)
.create(Service.class)
.getYoutubeInfo(“v=r2qd\u KPQiZE&t=31s”)
.enqueue(新的回调函数(){
@凌驾
公共void onResponse(调用、响应){
if(response.issusccessful()){
Log.e(“TAG”,“youtube响应getYoutubeInfo:”+Response.body().toString());
}否则{
Log.e(“TAG”,“youtube响应getYoutubeInfo:error:”+Response.code());
}
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
}
});
以及日志拦截器:

2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: vary: Origin
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: vary: X-Origin
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: content-type: application/json; charset=UTF-8
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: date: Fri, 30 Aug 2019 00:32:23 GMT
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: expires: Fri, 30 Aug 2019 00:32:23 GMT
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: cache-control: private, max-age=0
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: x-content-type-options: nosniff
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: x-frame-options: SAMEORIGIN
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: x-xss-protection: 1; mode=block
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: server: GSE
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: alt-svc: quic=":443"; ma=2592000; v="46,43,39"
2019-08-30 07:32:23.680 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: {
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:  "error": {
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:   "errors": [
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:    {
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:     "domain": "usageLimits",
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:     "reason": "ipRefererBlocked",
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:     "message": "The request did not specify any Android package name or signing-certificate fingerprint. Please ensure that the client is sending them or use the API Console to update your key restrictions.",
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:     "extendedHelp": "https://console.developers.google.com/apis/credentials?project=XXXXXXX"
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:    }
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:   ],
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:   "code": 403,
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:   "message": "The request did not specify any Android package name or signing-certificate fingerprint. Please ensure that the client is sending them or use the API Console to update your key restrictions."
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:  }
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: }
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: <-- END HTTP (639-byte body)
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp: <-- 403 https://www.googleapis.com/youtube/v3/videos?key=AIzaSyCd71dtBE9gQhALXOOGo6krGT9F8A7IHJM&part=snippet,contentDetails,statistics,status&video_id=v%3Dr2qd_KPQiZE%26t%3D31s (256ms)
2019-08-3007:32:23.6791683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:vary:Origin
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:vary:X-Origin
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:content-type:application/json;字符集=UTF-8
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:日期:2019年8月30日星期五00:32:23 GMT
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:expires:2019年8月30日星期五00:32:23 GMT
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:cache-control:private,max-age=0
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:x-content-type-options:nosniff
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:x-frame-options:SAMEORIGIN
2019-08-3007:32:23.6791683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:x-xss-protection:1;模式=块
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:server:GSE
2019-08-30 07:32:23.679 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:alt svc:quic=“:443”;ma=2592000;v=“46,43,39”
2019-08-30 07:32:23.680 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:{
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:“错误”:{
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:“错误”:[
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:{
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:“域”:“usageLimits”,
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:“原因”:“IPRefererBlock”,
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:“消息”:“请求未指定任何Android软件包名称或签名证书指纹。请确保客户端正在发送它们或使用API控制台更新您的密钥限制。”,
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:“扩展帮助”:https://console.developers.google.com/apis/credentials?project=XXXXXXX"
2019-08-3007:32:23.6811683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:}
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:],
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:“代码”:403,
2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:“消息”:“请求未指定任何Android软件包名称或签名证书指纹。请确保客户端正在发送它们或使用API控制台更新您的密钥限制。”
2019-08-3007:32:23.6811683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:}
2019-08-3007:32:23.6811683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:}

2019-08-30 07:32:23.681 1683-1760/id.lkmsbwm.bwmmobile.dev D/OkHttp:根据您的日志,您的应用程序未在开发人员控制台上注册请首先使用包名进行检查

import com.google.api.client.auth.oauth2.Credential;
导入com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
导入com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
导入com.google.api.client.googleapis.auth.oauth2.googleaauthorizationcodeflow;
导入com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
导入com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
导入com.google.api.client.googleapis.json.GoogleJsonResponseException;
导入com.google.api.client.http.javanet.NetHttpTransport;
导入com.google.api.client.json.JsonFactory;
导入com.google.api.client.json.jackson2.JacksonFactory;
导入com.google.api.services.youtube.youtube;
导入com.google.api.services.youtube.model.VideoListResponse;
导入java.io.IOException;
导入java.io.InputStream;
导入java.io.InputStreamReader;
导入java.security.GeneralSecurityException;
导入java.util.array;
导入java.util.Collection;
公共类API示例{
私有静态最终字符串CLIENT\u SECRETS=“CLIENT\u secret.json”;
私有静态最终收集作用域=
Arrays.asList(“https://www.googleapis.com/auth/youtube.readonly");
私有静态最终字符串应用程序\u NAME=“API代码示例”;
私有静态最终JsonFactory JSON_FACTORY=JacksonFactory.getDefaultInstance();
/**
*创建授权凭据对象。
*
*@返回授权凭证对象。
*@抛出异常
*/
公共静态凭据授权(最终NetHttpTransport httpTransport)引发IOException{
//加载客户端机密。
InputStream in=apexample.class.getResourceAsStream(客户端密码);
谷歌客户机密=
load(JSON_工厂,新的InputStreamReader(in));
//构建流和触发器
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;

import com.google.api.services.youtube.YouTube;
import com.google.api.services.youtube.model.VideoListResponse;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Collection;

public class ApiExample {
    private static final String CLIENT_SECRETS= "client_secret.json";
    private static final Collection<String> SCOPES =
        Arrays.asList("https://www.googleapis.com/auth/youtube.readonly");

    private static final String APPLICATION_NAME = "API code samples";
    private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

    /**
     * Create an authorized Credential object.
     *
     * @return an authorized Credential object.
     * @throws IOException
     */
    public static Credential authorize(final NetHttpTransport httpTransport) throws IOException {
        // Load client secrets.
        InputStream in = ApiExample.class.getResourceAsStream(CLIENT_SECRETS);
        GoogleClientSecrets clientSecrets =
          GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
        // Build flow and trigger user authorization request.
        GoogleAuthorizationCodeFlow flow =
            new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, SCOPES)
            .build();
        Credential credential =
            new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
        return credential;
    }

    /**
     * Build and return an authorized API client service.
     *
     * @return an authorized API client service
     * @throws GeneralSecurityException, IOException
     */
    public static YouTube getService() throws GeneralSecurityException, IOException {
        final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
        Credential credential = authorize(httpTransport);
        return new YouTube.Builder(httpTransport, JSON_FACTORY, credential)
            .setApplicationName(APPLICATION_NAME)
            .build();
    }

    /**
     * Call function to create API service object. Define and
     * execute API request. Print API response.
     *
     * @throws GeneralSecurityException, IOException, GoogleJsonResponseException
     */
    public static void main(String[] args)
        throws GeneralSecurityException, IOException, GoogleJsonResponseException {
        YouTube youtubeService = getService();
        // Define and execute the API request
        YouTube.Videos.List request = youtubeService.videos()
            .list("snippet,contentDetails,statistics");
        VideoListResponse response = request.setId("Ks-_Mh1QhMc").execute();
        System.out.println(response);
    }
}
Api.getClient(context)
            .create(Service.class)
            .getYoutubeInfo("v=r2qd_KPQiZE&t=31s")
            .enqueue(new Callback<JsonObject>()
Api.getClient(context)
            .create(Service.class)
            .getYoutubeInfo("r2qd_KPQiZE")
            .enqueue(new Callback<JsonObject>()