私は自分のYouTubeアカウントにファイルをアップロードしようとしていますが、何とかそれを動作させることができません。 ご協力いただければ幸いです。ここで youtube api upload file - この操作に必要な開発者キー
は私のコードです:public class YouTubeUploadService {
String apiKey = "real-dev-api-key";
String uName = "user_name";
String uPassword= "user_password";
public static void uploadVideo() throws Exception{
YouTubeService service2 = new YouTubeService("olala", apiKey);
try {
service2.setUserCredentials("uName", "uPassword");
} catch (AuthenticationException e) {
System.out.println("Invalid login credentials.");
System.exit(1);
}
System.out.println(service2.getVersion());
UserProfileEntry userProfileEntry = service2.getEntry(new URL(profileUrl), UserProfileEntry.class);
System.out.println(userProfileEntry.getAge());
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent("My Test Movie");
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Autos"));
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("key word 1");
mg.getKeywords().addKeyword("key word 2");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent("plain text");
mg.setPrivate(false);
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "tag scheme1 "));
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "tag scheme 2"));
newEntry.setGeoCoordinates(new GeoRssWhere(37.0,-122.0));
newEntry.setLocation("Mountain View, CA");
MediaFileSource ms = new MediaFileSource(new File("Wildlife.wmv"), "video/quicktime");
newEntry.setMediaSource(ms);
String uploadUrl = "https://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
System.out.println("Uploading");
VideoEntry createdEntry = service2.insert(new URL(uploadUrl), newEntry);
createdEntry.update();
System.out.println("Done ---- Uploading");
}
}
私はこのコードを実行するとき、私は得る:私は試して削除すると、この操作
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:605)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.media.MediaService.insert(MediaService.java:400)
...
ために必要
Exception in thread "main" com.google.gdata.util.ServiceForbiddenException: Developer key required for this operation
のGData ServiceForbiddenException
Developerキー{}コードでブロックをキャッチ "service2.setUserCredentials(" uName "、" uPassword ");"このエラーが発生します:
Exception in thread "main" com.google.gdata.util.AuthenticationException: Unauthorized
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:608)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.media.MediaService.insert(MediaService.java:400)...
私はここで何が欠けていますか? Googleのドキュメントからこのコードを入手しました。 アカウントへのアクセスをどこかで許可する必要がありますか?もし私がGoogleの文書でそれを見つけることができないので、どのように説明してください。
私はそれを修正しました。問題は、私が値を注入している方法でした: 文字列apiKey = "real-dev-api-key";アウェイ、これは今働く。新しい心。 – aki