我正在尝试使用gdata objectivec客户端库实现对YouTube视频的评论,使用此线程中发布的代码片段;副本如下:
- (void)addCommentTitle:(NSString *)commentTitle
text:(NSString *)commentContent
toVideo:(GDataEntryYouTubeVideo *)entry {
GDataComment *commentObj = [entry comment];
GDataFeedLink *feedLink = [commentObj feedLink];
NSURL *feedURL = [feedLink URL];
if (feedURL) {
// fetch the comment feed for the video
GDataServiceGoogleYouTube *service = [self youTubeService];
[service fetchFeedWithURL:feedURL
completionHandler:^(GDataServiceTicket *ticket, GDataFeedBase *commentFeed, NSError *error) {
// callback
//
// insert a new comment into the comment feed
if (error == nil) {
GDataEntryYouTubeComment *newCommentEntry = [GDataEntryYouTubeComment commentEntry];
[newCommentEntry setTitleWithString:commentTitle];
[newCommentEntry setContentWithString:commentContent];
NSURL *postURL = [[commentFeed postLink] URL];
[service fetchEntryByInsertingEntry:newCommentEntry
forFeedURL:postURL
completionHandler:^(GDataServiceTicket *ticket, GDataEntryBase *entry, NSError *error) {
// callback
if (error == nil) {
// succeeded
}
}];
}
}];
}
}
但我总是得到以下例外:
*** Assertion failure in -[GDataObject setContentStringValue:](), XXXXXXXX/GData/BaseClasses/GDataObject.m:2353
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'GDataEntryYouTubeComment setting undeclared content value'
幸运的是,我在设置评论内容之前添加了一个新的调用,成功地消除了这种情况:
GDataEntryYouTubeComment* newCommentEntry = [GDataEntryYouTubeComment commentEntry];
[newCommentEntry addContentValueDeclaration]; // <--- this method does the trick
[newCommentEntry setTitleWithString:commentTitle];
[newCommentEntry setContentStringValue:commentContent];
但它仍然不好,因为请求现在从服务器反弹回来,并出现以下错误:
serviceBase:<GDataServiceGoogleYouTube: 0x7a73eb0>
objectFetcher:GTMHTTPFetcher 0x7c75b20 (https://gdata.youtube.com/feeds/api/videos/XXXXXXXXXX/comments)
failedWithStatus:400
data:<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>ParseException</code><internalReason>[Line 2, Column 514, element entry] No converter for type class java.lang.Void</internalReason></error><error><domain>GData</domain><code>missingConverter</code><internalReason>No converter for type class java.lang.Void</internalReason></error></errors>
有其他人遇到过这个问题吗?这是我的错误还是谷歌的错误?
原来上面的代码是正确的,在我的代码中我拼错了
[newCommentEntry setContentWithString:commentContent];
并使用
[newCommentEntry setContentStringValue:commentContent];
相反。现在它运行良好。