2017-04-18 1 views
2

YouTube에 특정 YouTube 계정으로 비디오를 업로드해야합니다. 그래서 내가 자바 구글 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 놀이터에서 계정에 대한 새로 고침 토큰을 얻고 필요하면 언제든지 액세스 토큰을 가져 오는 것입니다. 이 작업을 수행하는 단계는 How do I authorise an app (web or installed) without user intervention? (canonical ?)에 열거됩니다. 댓글에는 YouTube 동영상에 대한 링크가 있으며 단계에 대해서도 설명되어 있습니다.