gpt4 book ai didi

android - YouTube视频上传显示某些用户 “Required parameter: part”错误

转载 作者:行者123 更新时间:2023-12-03 05:54:31 27 4
gpt4 key购买 nike

我试图找出为什么我们的某些用户在尝试使用YouTube API v3将视频上传到YouTube时出现"Required parameter: part"错误的原因。您可以在下面看到我们用于上传视频的代码。方法参数是长度不短或太长的有效字符串。

int shareYoutube(@NonNull Uri mediaUri, String mime, String mediaTitle, String postMessage, String accountName)
{
int error = ERR_NO_ERROR;

try {
// Developer tags not supported yet
//https://code.google.com/p/gdata-issues/issues/detail?id=5012

// Authorize the request.
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(getApplicationContext(), Arrays.asList(YouTubeScopes.YOUTUBE_UPLOAD));
credential.setSelectedAccountName(accountName);

// This object is used to make YouTube Data API requests.
YouTube.Builder builder = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential);
builder.setApplicationName("TEST APP");
YouTube youtube = builder.build();

// Add extra information to the video before uploading.
Video video = new Video();

// set privacy
VideoStatus status = new VideoStatus();
status.setPrivacyStatus("public");
video.setStatus(status);

// Most of the video's metadata is set on the VideoSnippet object.
VideoSnippet snippet = new VideoSnippet();
snippet.setTitle(mediaTitle);
snippet.setDescription(postMessage);

// Film & Animation https://gist.github.com/dgp/1b24bf2961521bd75d6c
snippet.setCategoryId("1");

// Set the keyword tags that you want to associate with the video.
List<String> tags = new ArrayList<>();
tags.add("animation");
tags.add("cartoon");
tags.add("2d animation");
tags.add("drawing");
snippet.setTags(tags);

// Add the completed snippet object to the video resource.
video.setSnippet(snippet);

String fileFormat = "video/*";
InputStreamContent mediaContent = new InputStreamContent(fileFormat, getContentResolver().openInputStream(mediaUri));

// Insert the video. The command sends three arguments. The first
// specifies which information the API request is setting and which
// information the API response should return. The second argument
// is the video resource that contains metadata about the new video.
// The third argument is the actual video content.
YouTube.Videos.Insert videoInsert = youtube.videos().insert("snippet,statistics,status", video, mediaContent);

// Insert to a channel
//videoInsert.setOnBehalfOfContentOwnerChannel();

// Set the upload type and add an event listener.
MediaHttpUploader uploader = videoInsert.getMediaHttpUploader();

// Indicate whether direct media upload is enabled. A value of
// "True" indicates that direct media upload is enabled and that
// the entire media content will be uploaded in a single request.
// A value of "False," which is the default, indicates that the
// request will use the resumable media upload protocol, which
// supports the ability to resume an upload operation after a
// network interruption or other transmission failure, saving
// time and bandwidth in the event of network failures.
uploader.setDirectUploadEnabled(false);

YouTubeCallbackListener callback = new YouTubeCallbackListener();
uploader.setProgressListener(callback);

// Call the API and upload the video.
Video returnedVideo = videoInsert.execute();

synchronized (callback) {
if (!callback.hasCallbackResult()) {
try {
callback.wait();
error = callback.error;
} catch (InterruptedException e) {
e.printStackTrace();
error = ERR_POST_CANCELED;
}
} else {
error = callback.error;
}
}

if (ERR_NO_ERROR == error && null != returnedVideo)
{
Intent notificationIntent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://www.youtube.com/watch?v="+returnedVideo.getId()));

mPendingIntent = PendingIntent.getActivity(getBaseContext(), 0, notificationIntent, 0);
}

}
catch (UserRecoverableAuthIOException userRecoverableException)
{
error = ERR_UNABLE_TO_AUTH_ACCOUNT;
try {
GoogleAuthUtil.getTokenWithNotification(
getApplicationContext(), accountName, "oauth2:" + YouTubeScopes.YOUTUBE_UPLOAD, null);
} catch (IOException e) {
} catch (GoogleAuthException e) {
}
} catch (GoogleJsonResponseException e) {
error = ERR_POST_ERROR;
Crashlytics.logException(e);
} catch (IOException e) {
error = ERR_POST_ERROR;
Crashlytics.logException(e);
} catch (Throwable t) {
error = ERR_POST_ERROR;
Crashlytics.logException(t);
}

return error;
}

错误:
400 Bad Request { "errors" : [ { "domain" : "global", "reason" : "required", "message" : "Required parameter: part", "locationType" : "parameter", "location" : "part" } ], "code" : 400, "message" : "Required parameter: part" } 

对这里可能发生的事情有任何想法吗?

最佳答案

问题是我们的proguard脚本。我们要做的就是在其中添加以下行。

-keep class com.google.api.** { *; } 

关于android - YouTube视频上传显示某些用户 “Required parameter: part”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49338453/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com