签名apk中的Youtube数据api错误?

时间:2017-10-28 20:56:59

标签: android youtube youtube-api

我正在尝试实现从Android应用添加订阅到youtube频道的功能。

我已经完成了:

  1. 在开发者控制台上注册应用。 - 完成
  2. 包名和SHA-1证书指纹。完成度的数 Image

  3. 使用" https://www.googleapis.com/auth/youtube"进行Google帐户帐户身份验证。完成度的数

  4. 注意:在调试模式下,功能正常。

    问题:当我在Play商店创建一个签名的apk用于发布应用程序时,订阅按钮不工作每次都会抛出不同的错误。

    使用不受限制的api密钥

    W/System.err: {
    "c" : 0,
       "errors" : [ {
        "domain" : "global",
         "reason" : "required",
         "message" : "Required parameter: part",
        "locationType" : "parameter",
       "location" : "part"
       } ],
       "code" : 400,
       "message" : "Required parameter: part"
     } 
    

    这是我正在做的代码

      // Initialize credentials and service object.
            mCredential = GoogleAccountCredential.usingOAuth2(getApplicationContext(), Arrays.asList(SCOPES)).setBackOff(new ExponentialBackOff());
    
     HttpTransport transport = AndroidHttp.newCompatibleTransport();
    
                        JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    
    
                        YouTube mService = new YouTube.Builder(transport, jsonFactory, mCredential)
                                .setApplicationName(getResources().getString(R.string.app_name))
                                .setYouTubeRequestInitializer(new YouTubeRequestInitializer(Config.KEY))
                                .build();
    
    
     channelId = myListModel.getYoutubeChannelId();
    // Create a resourceId that identifies the channel ID.
                            ResourceId resourceId = new ResourceId();
                            resourceId.setChannelId(channelId);
                            resourceId.setKind("youtube#channel");
    
    
     // Create a snippet that contains the resourceId.
                            SubscriptionSnippet snippet = new SubscriptionSnippet();
                            snippet.setResourceId(resourceId);
    
                            // Create a request to add the subscription and send the request.
                            // The request identifies subscription metadata to insert as well
                            // as information that the API server should return in its response.
                            Subscription subscription = new Subscription();
    
                            subscription.setSnippet(snippet);
    
                            YouTube.Subscriptions.Insert subscriptionInsert = mService.subscriptions().insert("snippet,contentDetails", subscription);
    
                            try {
                                Subscription returnedSubscription = subscriptionInsert.execute();
    
                                // Print information from the API response.
                                System.out.println("\n================== Returned Subscription ==================\n");
    
                                System.out.println("  - Id: " + returnedSubscription.getId());
    
                                System.out.println("  - Title: " + returnedSubscription.getSnippet().getTitle());
    
                                addSubscriber(myListModel);
    
                            } catch (UserRecoverableAuthIOException mLastError) {
    
                                startActivityForResult(mLastError.getIntent(), REQUEST_AUTHORIZATION);
    
                            }
    
                        } catch (GoogleJsonResponseException e) {
                            System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : "
                                    + e.getDetails().getMessage());
                            e.printStackTrace();
    
    
                        } catch (IOException e) {
                            System.err.println("IOException: " + e.getMessage());
                            e.printStackTrace();
    
                        } catch (Throwable t) {
                            System.err.println("Throwable: " + t.getMessage());
                            t.printStackTrace();
    
                        }
    

0 个答案:

没有答案