2017-08-05 31 views
0

要使用此的Youtube API如何得到的答覆意見和喜歡

評論線程獲取評論:列表

GET https://www.googleapis.com/youtube/v3/commentThreads?part=snippet

{ 
"error": { 
    "errors": [ 
    { 
    "domain": "usageLimits", 
    "reason": "dailyLimitExceededUnreg", 
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.", 
    "extendedHelp": "https://code.google.com/apis/console" 
    } 
    ], 
    "code": 403, 
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup." 
} 
} 

但是,如何讓每個評論回覆,並檢查用戶喜歡它或不,知道嗎?

回答

0

您可以在檢索評論回覆使用comments.list method。下面是一個example

// Call the YouTube Data API's comments.list method to retrieve 
// existing comment 
// replies. 
       CommentListResponse commentsListResponse = youtube.comments().list("snippet") 
         .setParentId(parentId).setTextFormat("plainText").execute(); 
       List<Comment> comments = commentsListResponse.getItems(); 

       if (comments.isEmpty()) { 
        System.out.println("Can't get comment replies."); 
       } else { 
        // Print information from the API response. 
        System.out 
          .println("\n================== Returned Comment Replies ==================\n"); 
        for (Comment commentReply : comments) { 
         snippet = commentReply.getSnippet(); 
         System.out.println(" - Author: " + snippet.getAuthorDisplayName()); 
         System.out.println(" - Comment: " + snippet.getTextDisplay()); 
         System.out 
           .println("\n-------------------------------------------------------------\n"); 
        } 
        Comment firstCommentReply = comments.get(0); 
        firstCommentReply.getSnippet().setTextOriginal("updated"); 
        Comment commentUpdateResponse = youtube.comments() 
          .update("snippet", firstCommentReply).execute(); 
        // Print information from the API response. 
        System.out 
          .println("\n================== Updated Video Comment ==================\n"); 
        snippet = commentUpdateResponse.getSnippet(); 
        System.out.println(" - Author: " + snippet.getAuthorDisplayName()); 
        System.out.println(" - Comment: " + snippet.getTextDisplay()); 
        System.out 
          .println("\n-------------------------------------------------------------\n"); 

至於喜歡,你可能要檢查出snippet.viewerRating

觀衆已經給這個評論的評級。請注意,這家酒店目前並不確定dislike的收視率,但這種行爲可能會改變。在此期間,該屬性值是like如果觀衆評爲評論積極。該值是被給沒有在其他情況下,包括用戶評論負面的評級或者沒有評級的評論。該物業

有效值:

  • 沒有

然後檢查snippet.likeCount得到喜歡的總數(正面評級)的評論已收到。

這裏的sample JSON structure,顯示了comments資源的格式。

{ 
    "kind": "youtube#comment", 
    "etag": etag, 
    "id": string, 
    "snippet": { 
    ...... 
    "authorChannelId": { 
     "value": string 
    }, 
    ...... 
    "viewerRating": string, 
    "likeCount": unsigned integer, 
    ...... 
    } 
} 

希望這有助於!

相關問題