Created
August 13, 2024 16:08
-
-
Save soyuka/f52aa1a14f86bdf5c55767f5c686a7ba to your computer and use it in GitHub Desktop.
Use facebook upload api with symfony http client (warning this endpoint is not yet supported by facebook's own endpoints)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$uploadSession = $this->metaClient->request('POST', sprintf('%s/uploads', $this->metaAppId), [ | |
'query' => [ | |
'file_name' => $mediaObject->getFilePath(), | |
'file_length' => $mediaObject->getContentSize(), | |
'file_type' => $mediaObject->getMimeType(), | |
'access_token' => $credential->getAccessToken(), | |
'appsecret_proof' => $this->secretProof($credential->getAccessToken()), | |
], | |
])->toArray(); | |
if (!isset($uploadSession['id'])) { | |
throw new BroadcastServiceProviderException('Error while creating upload session'); | |
} | |
$handle = $this->metaClient->request('POST', '/' . $uploadSession['id'], [ // / is important see https://github.com/symfony/symfony/issues/54332 | |
'headers' => [ | |
'file_offset' => '0', | |
'content-length' => $mediaObject->getContentSize(), | |
], | |
'body' => $this->mediaStorage->readStream($mediaObject->getFilePath()), | |
'query' => [ | |
'access_token' => $credential->getAccessToken(), | |
'appsecret_proof' => $this->secretProof($credential->getAccessToken()), | |
], | |
])->toArray(); | |
return $handle['h']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment