-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload function returns false... #68
Comments
No PHP code, I can't exactly help you... What type of image are you trying to upload (JPEG / GIF /PNG), file size, dimensions ? Are you authenticated correctly ? |
I'll post my basic code below: <?PHP
include_once "auth.php";
include_once 'dependencies/snapchat.php';
if (isset($_POST['submit'])){
$imagedata = file_get_contents($_FILES['image']['tmp_name']);
echo '<br><img alt="Embedded Image" src="data:image/png;base64,' . base64_encode($imagedata) . '" />';
//$imagedata = gzencode($imagedata);
$sendid = $snapchat->upload(0, $imagedata);
echo "<br>Send ID: " . ($sendid) . ".";
$sendstory = $snapchat->setStory($sendid, Snapchat::MEDIA_IMAGE, 10);
echo "<br>Send Story Result: " . ($sendid != "" ? "true" : "false");
}else{
echo "<form method=\"post\" enctype=\"multipart/form-data\">
Select image to upload:
<input type=\"file\" name=\"image\" id=\"image\">
<input type=\"submit\" value=\"Upload Image\" name=\"submit\">
</form>";
}
?> Auth.php <?PHP
include_once "dependencies/snapchat.php";
$snapchat = new Snapchat('MY_USERNAME',null,'VALID_ACCESS_TOKEN');
if (!$snapchat->username) {
$snapchat = new Snapchat('MY_USERNAME','MY_PASSWORD');
}
?> And I just tried uploading this basic image: http://www.library.nuigalway.ie/media/training/afternoon/jpeg.jpg |
You need to do more error checking, what happens if your |
I am using the lastest version! And that is my problem, the upload function always returns false, rather than an ID. My $snapchat->upload function looks like this: public function upload($type, $data) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
throw new Exception('Not logged in...');
}
// To make cURL happy, we write the data to a file first.
$temp = tempnam(sys_get_temp_dir(), 'Snap');
file_put_contents($temp, parent::encryptECB($data));
if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
$cfile = curl_file_create($temp, ($type == self::MEDIA_IMAGE ? 'image/jpeg' : 'video/quicktime'), 'snap');
}
$media_id = strtoupper($this->username) . '~' . time();
$timestamp = parent::timestamp();
$result = parent::post(
'/upload',
array(
'media_id' => $media_id,
'type' => $type,
'data' => (version_compare(PHP_VERSION, '5.5.0', '>=') ? $cfile : '@' . $temp . ';filename=data'),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
),
TRUE
);
unlink($temp);
return is_null($result) ? $media_id : FALSE;
} And the problem is that the function doesn't return the media_id, which should mean that the $result is not null. I alter the last line so I can see what the $result is(because it's not null) and it comes back as a boolean that is false. if ($result === FALSE || curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200) {
curl_close($ch);
return FALSE;
} Specifically from this part of the if statement: curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200
|
The current upload function is broken, I just tested my own code that had previously worked, we need to upgrade to the latest endpoint to get it working. |
I've got the upload and send function to work on the new endpoint, here is my testing code : http://files.lab.cuonic.com/NWI2MzJ |
I have tried using multiple different accounts, different PHP hosts(to eliminate issues with my IP), and even very basic code, however it never is able to upload an image...
The text was updated successfully, but these errors were encountered: