Youtube Api率(喜欢不喜欢)发布请求不起作用

时间:2016-10-22 15:17:46

标签: php youtube youtube-api youtube-data-api

我想用Youtube Data Api发布费率。我发布了此链接curl:https://www.googleapis.com/youtube/v3/videos/rate?access_token=xxxxTOKENxxxxx&id=xxxxVIDEO_IDxxxxx&rating=dislike&key=xxxxAPI_KEYxxxxx

此请求返回204 HTTP代码。但是当我检查视频时,费率统计不会改变。我在哪里做错了?

我使用Google PHP Library撰写了差价发布请求。这些是我的代码;

session_start();
require_once 'vendor/autoload.php';

$client = new Google_Client();
$client->setAuthConfig('client.json');
$scope = "https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtube.readonly https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtubepartner https://www.googleapis.com/auth/youtubepartner-channel-audit";
$client->addScope($scope);
$client->setRedirectUri('http://localhost/youtube/islem.php');

if (isset($_GET['code'])) {
    $client->authenticate($_GET['code']);

    $access_token = $client->getAccessToken();
    $_SESSION['access_token'] = $client->getAccessToken();
    header("Location: islem.php");
} else {
    $client->setAccessToken($_SESSION['access_token']);
}

$videoID = "xxxxxxxxx";
$youtube = new Google_Service_YouTube($client);
$result = $youtube->videos->rate($videoID, "like");

print_r($result);

1 个答案:

答案 0 :(得分:0)

这对我有用。我尝试了Videos.rate Try-It并填写了必要的细节,但它确实有效。通过获取videoId,我能够在Youtube上欣赏随机视频。我使用了Try-it来删除它(竖起大拇指),它仍然可以正常工作。

尝试在按EXECUTE按钮时生成的Try-It中使用URI请求。确保您也登录Youtube。