Ich möchte ein Video direkt auf Youtube von meinem Server, für den ich PHP curl bin, hochladen.PHP curl ändert den Inhaltstyp in application/x-www-form-urlencoded. Sollte das nicht tun
Ich brauche diese Anfrage Format:
POST /feeds/api/users/default/uploads HTTP/1.1
Host: uploads.gdata.youtube.com
Authorization: Bearer ACCESS_TOKEN
GData-Version: 2
X-GData-Key: key=adf15ee97731bca89da876c...a8dc
Slug: video-test.mp4
Content-Type: multipart/related; boundary="f93dcbA3"
Content-Length: 1941255
Connection: close
--f93dcbA3
Content-Type: application/atom+xml; charset=UTF-8
<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<media:group>
<media:title type="plain">Bad Wedding Toast</media:title>
<media:description type="plain">
I gave a bad toast at my friend's wedding.
</media:description>
<media:category
scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People
</media:category>
<media:keywords>toast, wedding</media:keywords>
</media:group>
</entry>
--f93dcbA3
Content-Type: video/mp4
Content-Transfer-Encoding: binary
<Binary File Data>
--f93dcbA3--
Das ist, was ich habe:
$content = $this->buildRequestContent();
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads',
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_BINARYTRANSFER => true,
CURLOPT_POSTFIELDS => $content,
CURLOPT_HTTPHEADER, array(
"Authorization" => sprintf("GoogleLogin auth=%s", $this->accessToken),
"GData-Version" => 2,
"X-GData-Key" => sprintf("key=%s", $this->developerKey),
"Slug" => sprintf("%s", $this->video->getFilename()),
"Content-Type" => sprintf("multipart/related; boundary=\"%s\"", $this->boundaryString),
"Content-Length" => strlen($content),
"Connection" => "close"
),
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
Dumping das Ergebnis zeigt mir, dass Locke die Content-Type
zu application/x-www-form-urlencoded
geändert, was natürlich nicht von youtube unterstützt .
Ich bin meine binäre Inhalte (das Video) in CURLOPT_POSTFIELDS
, vielleicht ist das falsch, aber ich weiß nicht, wie Sie den Anfragekörper anders als das einstellen.
Wie behalte ich meinen Inhaltstyp, den ich einstelle?
Gemäß der Dokumentation 'CURLOPT_POST' wird der' Content-Type' automatisch auf 'application/x-www-form-urlencoded' gesetzt. Versuchen Sie vielleicht, diese Option und den 'CURLOPT_HEADER' in einzelnen Anweisungen zu setzen, oder zumindest letzteres in einer einzigen Anweisung mit 'curl_setopt' * nach * der Methode. – Havelock
Arbeitete. Könnten Sie das als Antwort posten, damit ich es akzeptieren kann? –