Search code examples
iosyoutubecommentsyoutube-apigdata

iOS GData YouTube comment on a Video


There are a lot of GData YouTube tutorials on how to upload a Video in an iOS App, but I didn't find one showing how to comment on a Video. So I read on the reference-page, just tried and so on but didn't find anything!

Does anyone know how to comment on a Video in an iOS App using the GData API?

Thanks


Solution

  • Use this methods in comment button

    GDataEntryYouTubeVideo *video = (GDataEntryYouTubeVideo *)arrayData;
    [self addCommentTitle:@"comment" text:commentField.text toVideo:video];
    
    
    - (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 setYouTubeDeveloperKey:devKey];
            [service setAuthToken:[self getRequestToken]];
            [service fetchFeedWithURL:feedURL completionHandler:^(GDataServiceTicket *ticket, GDataFeedBase *commentFeed,NSError *error) {
            if (error == nil) {
                            GDataEntryYouTubeComment *newCommentEntry = [GDataEntryYouTubeComment commentEntry];
                    [newCommentEntry addContentValueDeclaration];
                    [newCommentEntry setTitleWithString:commentTitle];
                    [newCommentEntry setContentWithString:commentContent];
                    NSString *subString = [videoString substringWithRange: NSMakeRange(0, [videoString rangeOfString: @"?"].location)];
                    NSString *last=[subString lastPathComponent];
                    NSString *ss=@"http://gdata.youtube.com/feeds/api/videos/";
                    NSString *idd=@"/comments";
                    NSString *com=[NSString stringWithFormat:@"%@%@%@",ss,last,idd];
                    NSURL *postURL = [NSURL URLWithString:com ];
                    [service fetchEntryByInsertingEntry:newCommentEntry
                                                     forFeedURL:postURL
                                              completionHandler:^(GDataServiceTicket *ticket, GDataEntryBase *entry, NSError *error) {
                                                  // callback
                                                  if (error == nil) {
                                                      NSLog(@"url.: succeeded ");
                                                  }
                                              }];
                        }
              }];
        }
    }
    

    get Authentication token using login details

    - (NSString*) getRequestToken {
    // return your auth token as string
    }