का उपयोग कर यूट्यूब पर वीडियो अपलोड करें मैं PHP का उपयोग कर यूट्यूब में एक वीडियो अपलोड करने की कोशिश कर रहा हूं। मैं यूट्यूब एपीआई v3 का उपयोग कर रहा हूं और मैं Google एपीआई PHP क्लाइंट लाइब्रेरी के नवीनतम चेक आउट स्रोत कोड का उपयोग कर रहा हूं।
मैं प्रमाणीकरण करने के लिए
https://code.google.com/p/google-api-php-client/ पर दिए गए नमूना कोड का उपयोग कर रहा हूं। प्रमाणीकरण ठीक से चला जाता है लेकिन जब मैं एक वीडियो अपलोड करने का प्रयास करता हूं तो मुझे Google_ServiceException
त्रुटि कोड 500 और शून्य के रूप में संदेश मिलता है।यूट्यूब एपीआई वी 3 और PHP
मैंने पहले निम्नलिखित प्रश्नों पर एक नज़र डाली थी: Upload video to youtube using php client library v3 लेकिन स्वीकार्य उत्तर फ़ाइल डेटा को अपलोड करने के तरीके को निर्दिष्ट करने का वर्णन नहीं करता है।
मुझे एक और समान प्रश्न Uploading file with Youtube API v3 and PHP मिला, जहां टिप्पणी में यह उल्लेख किया गया है कि श्रेणी आईडी अनिवार्य है, इसलिए मैंने श्रेणी आईडी को स्निपेट में सेट करने का प्रयास किया लेकिन फिर भी यह एक ही अपवाद देता है।
मैंने प्रलेखन साइट (https://developers.google.com/youtube/v3/docs/videos/insert) पर पायथन कोड को भी संदर्भित किया, लेकिन मुझे क्लाइंट लाइब्रेरी में अगला_चंक फ़ंक्शन नहीं मिला। लेकिन मैंने त्रुटि कोड 500 प्राप्त करने पर पुनः प्रयास करने के लिए एक लूप (कोड स्निपेट में उल्लिखित) डालने का प्रयास किया, लेकिन सभी 10 पुनरावृत्तियों में मुझे एक ही त्रुटि मिलती है।
के बाद किया जाता है कोड का टुकड़ा मैं कोशिश कर रहा हूँ:
$youTubeService = new Google_YoutubeService($client);
if ($client->getAccessToken()) {
print "Successfully authenticated";
$snippet = new Google_VideoSnippet();
$snippet->setTitle = "My Demo title";
$snippet->setDescription = "My Demo descrition";
$snippet->setTags = array("tag1","tag2");
$snippet->setCategoryId(23); // this was added later after refering to another question on stackoverflow
$status = new Google_VideoStatus();
$status->privacyStatus = "private";
$video = new Google_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
$data = file_get_contents("video.mp4"); // This file is present in the same directory as the code
$mediaUpload = new Google_MediaFileUpload("video/mp4",$data);
$error = true;
$i = 0;
// I added this loop because on the sample python code on the documentation page
// mentions we should retry if we get error codes 500,502,503,504
$retryErrorCodes = array(500, 502, 503, 504);
while($i < 10 && $error) {
try{
$ret = $youTubeService->videos->insert("status,snippet",
$video,
array("data" => $data));
// tried the following as well, but even this returns error code 500,
// $ret = $youTubeService->videos->insert("status,snippet",
// $video,
// array("mediaUpload" => $mediaUpload);
$error = false;
} catch(Google_ServiceException $e) {
print "Caught Google service Exception ".$e->getCode()
. " message is ".$e->getMessage();
if(!in_array($e->getCode(), $retryErrorCodes)){
break;
}
$i++;
}
}
print "Return value is ".print_r($ret,true);
// We're not done yet. Remember to update the cached access token.
// Remember to replace $_SESSION with a real database or memcached.
$_SESSION['token'] = $client->getAccessToken();
} else {
$authUrl = $client->createAuthUrl();
print "<a href='$authUrl'>Connect Me!</a>";
}
यह कुछ है कि मैं गलत कर रहा हूँ है?
आप एक स्टैक ट्रेस पोस्ट कर सकते हैं:
यहाँ नमूना कोड है? मुझे संदेह है कि यह मुद्दा यह है: http://code.google.com/p/gdata-issues/issues/detail?id=3961 –
मैंने उस मुद्दे को भी देखा था।जब सत्य के रूप में पुन: प्रारंभ करने योग्य सेट किया जाता है, तो मुझे त्रुटि अपवाद के साथ "अपवादित अपवाद 'Google_Exception' संदेश के साथ 'पुनः प्रारंभ करने योग्य अपलोड शुरू करने में विफल" त्रुटि मिलती है, अन्यथा यह हमेशा त्रुटि कोड के साथ त्रुटि कोड 500 देता है। – jayendrap