2017-04-18 9 views
2

動画をyoutubeにアップロードする必要があります。だから、私はjava google libを使用していることを認証する必要があります。サーバーからのGoogle認証

  Credential credential = new GoogleCredential.Builder() 
      .setTransport(new ApacheHttpTransport()) 
      .setJsonFactory(new JacksonFactory()) 
      .setServiceAccountId("[email protected]") 
      .setClientSecrets("[email protected]", "xx") 
      .setServiceAccountPrivateKeyFromP12File(new File("xx.p12")) 
      .setServiceAccountScopes(scopes) 
      .setServiceAccountUser("[email protected]") 
      .build(); 

      youtube = new YouTube.Builder(credential.getTransport(), credential.getJsonFactory(), credential).setApplicationName(
      "tellews-app").build(); 
      Video returnedVideo = videoInsert.execute(); 
      YouTube.Videos.Insert videoInsert = youtube.videos() 
      .insert("snippet,statistics,status", videoObjectDefiningMetadata, mediaContent); 
      Video returnedVideo = videoInsert.execute(); 

し、エラーを取得::コードは次のようになります

IOException: 401 Unauthorized { "error" : "unauthorized_client", "error_description" : "Client is unauthorized to retrieve access tokens using this method." }

たぶん誰かが私が間違って

答えて

0

シンプルにやっているものを見ています。

サービスアカウントを使用しないでください。サービスアカウントは使用しないでください。

対象のYouTubeアカウントのアクセストークンを取得する必要があります。シンプルな方法は、Oauth PlaygroundからそのアカウントのRefresh Tokenを取得し、必要に応じてアクセストークンを取得することです。これを実行する手順は、How do I authorise an app (web or installed) without user intervention? (canonical ?)に列挙されています。コメントにはYouTubeのビデオへのリンクがあり、ステップについても説明しています。