0

我正在尝试使用此线程中发布的代码片段,使用gdata-objectivec-client库对 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>

有没有其他人遇到过这个问题?这是我的错误还是谷歌的错误?

4

1 回答 1

0

原来上面的代码是正确的,在我的代码中我拼错了

[newCommentEntry setContentWithString:commentContent];

并使用

[newCommentEntry setContentStringValue:commentContent];

反而。现在它工作正常。

于 2012-07-13T14:08:02.997 回答