2012-07-12 140 views
0

我想实现评论与gdata-objectivec-client库YouTube视频,使用的代码片段张贴在this thread;拷贝如下:发布评论失败

- (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> 

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

回答

0

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

[newCommentEntry setContentWithString:commentContent]; 

和使用

[newCommentEntry setContentStringValue:commentContent]; 

代替。现在它工作正常。

+0

非常感谢,官方文件真的让我失望;-) – 2012-10-25 14:34:43