JorgenPhi / php-snapchat

A PHP library for the Snapchat API - With Commit History
MIT License
259 stars 73 forks source link

Can't get snap to send! #63

Closed DanMossa closed 9 years ago

DanMossa commented 9 years ago
<?php

require_once('src/snapchat.php');

// Log in:
$snapchat = new Snapchat('XXX', 'XXX');

// Upload a snap and send it to me for 8 seconds:
$id = $snapchat->upload(
Snapchat::MEDIA_IMAGE,
file_get_contents('/images/arielol.jpg')
);
$snapchat->send($id, array('allenbgd'), 4);

// Log out:
$snapchat->logout();

?>

For whatever reason, nothing is being sent. And when I tried using the test I get an error saying "Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /snap/tests/phpSnapchatTest.php on line 3"

hako commented 9 years ago

This could be a header issue. Try this branch: #64

DanMossa commented 9 years ago

So I fixed that up and i tried sending a snapchat. It logged me out of snapchat which I'm assuming is correct, but then when I logged back in I don't see anything sent. I also tried it with uploading a story and I don't see anything I've uploaded.

Mxchael commented 9 years ago

@Dgameman1 How did you fix? I am still getting issues with updated headers.

DanMossa commented 9 years ago

@Spurlex I actually did not get it to work yet. Nothing is being sent at the moment =/

hako commented 9 years ago

@Dgameman1 Could you show me a sample of your code please, Also @Spurlex could you describe to me the issues you are having?

hako commented 9 years ago

I'm guessing you're using the API on the server, Does your code work locally?

DanMossa commented 9 years ago

@hako Neither one of these seem to be doing anything other than logging me out <?php

require_once('src/snapchat.php');

// Log in:
$snapchat = new Snapchat('XXX', 'XXX');

// Upload a snap and send it to me for 8 seconds:
//$id = $snapchat->upload(
//    Snapchat::MEDIA_IMAGE,
//    file_get_contents('/images/arielol.jpg')
//);
//$snapchat->send($id, array('allenbgd'), 4);

$id = $snapchat->upload(
    Snapchat::MEDIA_VIDEO,
    file_get_contents('/images/arielol.jpg')
);

// Log out:
$snapchat->logout();

?>
Snowlav commented 9 years ago

@Dgameman1

require_once('src/snapchat.php');

// Log in: $snapchat = new Snapchat('XXX', 'XXX');

// Upload a snap and send it to me for 8 seconds: $id = $snapchat->upload( Snapchat::MEDIA_IMAGE, file_get_contents('/images/arielol.jpg') ); $snapchat->send($id, array('allenbgd'), 4);

$id = $snapchat->upload( Snapchat::MEDIA_VIDEO, file_get_contents('/images/arielol.jpg') );

// Log out: $snapchat->logout();

?>

DanMossa commented 9 years ago

@Snowlav I just commented the send private snapchat just to show that I'm trying to only use one. That doesn't seem to work either lol

Snowlav commented 9 years ago

"Neither one of these seem to be doing anything other than logging me out" You put "//" in front of the entire area, I figured that was the problem haha, my bad.

DanMossa commented 9 years ago

@Snowlav Lol i wish it was that easy :(

DanMossa commented 9 years ago

Uh any ideas guys ?:O

KyleBoyer commented 9 years ago

Uh any ideas guys ?:O

I'm having a similar issue. Without digging a little deeper, I can't guarantee this, but my snaps won't upload... However, if they do upload, they send perfectly. When I dug more deeply, my POST function inside snapchat_agent would be returning false due to the CURL headers coming back as 401 Unauthorized.

DanMossa commented 9 years ago

@KyleBoyer How would you know that they send perfectly if they don't upload?

liamjack commented 9 years ago

The upload endpoint responds differently with the change of client version. I've just documented the latest version of the /ph/upload :

/ph/upload

Description

Used to upload media to the server

Request

Response

No content.

DanMossa commented 9 years ago

So what do you suggest I do? Just wait till it gets fixed? @cuonic

liamjack commented 9 years ago

You could try participating in the development of a solution, I've gave you the request and response parameters of the new upload system, you just need to change a few things in the PHP class.

On 02/01/2015 08:25, Dgameman1 wrote:

So what do you suggest I do? Just wait till it gets fixed? @cuonic https://github.com/cuonic

— Reply to this email directly or view it on GitHub https://github.com/JorgenPhi/php-snapchat/issues/63#issuecomment-68511930.

KyleBoyer commented 9 years ago

You could try participating in the development of a solution, I've gave you the request and response parameters of the new upload system, you just need to change a few things in the PHP class.

I just adjusted my code and tried those parameters with that endpoint, and I still get back a 401 Unauthorized response. The only thing that I could've screwed up with, was the features_map... I tried leaving that null.

liamjack commented 9 years ago

Got it working with a few modifications, here is my testing code : http://files.lab.cuonic.com/NWI2MzJ

DanMossa commented 9 years ago

@cuonic Page not found :O

liamjack commented 9 years ago

@Dgameman1 Page not found for the download, when uploading a snap, when sending the snap ?

DanMossa commented 9 years ago

@cuonic http://files.lab.cuonic.com/NWI2MzJ says 404 Not Found

liamjack commented 9 years ago

@Dgameman1 Sorry about that, seems to work for other people though. Try this : http://dev.cuonic.com/SnapUpload.zip

DanMossa commented 9 years ago

Hmm that's really strange. Still 404 http://i.imgur.com/jkBRQAn.png Let me try going through proxy

DanMossa commented 9 years ago

And it worked ... @cuonic Very weird. Thank you though! Let me try this out!

liamjack commented 9 years ago

@Dgameman1 Check your DNS servers they don't see very... up to date :) In upload.php you just need to add your Snapchat username and password for it to work.

DanMossa commented 9 years ago

@cuonic http://i.imgur.com/txR6m7H.png :( I promise I'm not retarded

liamjack commented 9 years ago

I've got exactly the same code and it's working good. If you're getting "Error encountered" then it's good news, it means that the upload was successful, so it's just the "sending" of the snap that screws up.

Use the following code to debug the sending :

<?php

if($_POST) {
    require_once("snapchat.php");

    $snapchat = new Snapchat();

    $login = $snapchat->login('USERNAME', 'PASSWORD');

    if(filesize($_FILES['image']['tmp_name']) > 1000000) {
        $message = "File too big.";
    } else {
        $upload = $snapchat->upload(Snapchat::MEDIA_IMAGE, file_get_contents($_FILES['image']['tmp_name']));

        if($upload['error'] == 1) {
            $message = $upload['message'];  
        } else {
            $return = $snapchat->send($upload['media_id'], array($_POST['username']), $_POST['seconds']);

            echo "<pre>";
            var_dump($return);
            echo "</pre>";

            if($return['error'] == 0) {
                $message = "Snap sent.";
            } else {
                $message = "Error encountered.";
            }
        }
    }
}

?>

And paste here what you get back in the

 tags

DanMossa commented 9 years ago

Um, now when I Just go to the page, i get this error http://i.imgur.com/HTMmo9n.png @cuonic

liamjack commented 9 years ago

Well that's good because now we know the problem. Either the file you are trying to send is not valid "media", try starting off by sending a small JPEG image, don't try videos / large images just yet. If not the the media type is invalid, try replacing Snapchat::MEDIA_IMAGE with 0 in upload.php

DanMossa commented 9 years ago

@cuonic I didn't actually fill out the form or anything. I just went to the page and it gave me that error =O

Like I didn't send an image yet

liamjack commented 9 years ago

Oh ok it's detecting a POST request by fetching the page... Oh dear. Replace Line 3 if($_POST) with if(isset($_POST['username'])) and don't refresh the page after posting, just call it from the address bar.

DanMossa commented 9 years ago

I changed the code and the same thing happens when i go to the page without posting lol http://i.imgur.com/fG5VcD4.png What if I make an ajax request and put the PHP into a different page? @cuoinic

liamjack commented 9 years ago

Damn, Ajax won't work for the file upload. How about changing line 3 to if($_SERVER['REQUEST_METHOD'] == "POST")

DanMossa commented 9 years ago

@cuonic same error =/ Is it working with you? And you're right about it posting just by refreshing. Because I get logged out just by refreshing =o

liamjack commented 9 years ago

The original code works for me as well as all the modifications.

liamjack commented 9 years ago

What browser are you using ? What web server ?

DanMossa commented 9 years ago

@cuonic I'm using google chrome and it's currently hosted up online

liamjack commented 9 years ago

Try running it locally with a WAMP / LAMP server

DanMossa commented 9 years ago

Okay cool! So, this time nothing happened and the page loaded fine. I fill everything out and I get this http://i.imgur.com/kleluAa.png but I didn't log out of snapchat nor did it send anything

liamjack commented 9 years ago

This is not working very well at all for you. Are you sure you are using the provided snapchat.php and snapchat_agent.php ? Try using the following file as snapchat.php : https://gist.github.com/cuonic/bb106e1ce978ebf71c6e

DanMossa commented 9 years ago

@cuonic This does not make any sense. I legit used the file you sent me to download but apparently the snapchat.php you just sent me to use on github is different. so I used that and now the error i get is this..

http://i.imgur.com/JfODLye.png

liamjack commented 9 years ago

Good, well something is screwing up with the login. Use the following as snapchat_agent.php : https://gist.github.com/cuonic/449a34af812fefc72522

DanMossa commented 9 years ago

Still get the same No Authentication Details =/

Just want to say thank you so much btw

DanMossa commented 9 years ago

But the thing is, it still logs me out :o

liamjack commented 9 years ago

Ok try adding the following :

echo "<pre>";
var_dump($login);
echo "</pre>";

just after $login = $snapchat->login("username", "password");

And paste the output here

DanMossa commented 9 years ago

http://i.imgur.com/FenPOEv.png

liamjack commented 9 years ago

There's the problem :) Try doing a Google search for that one

DanMossa commented 9 years ago

@cuonic So I'm assuming the script doesn't see ca_bundle.crt curl_setopt($ch, CURLOPT_CAINFO, 'ca_bundle.crt');

but ca_bundle.crt is with every other file? image

liamjack commented 9 years ago

@Dgameman1 : Curl requires an absolute path for the certificate file apparently, so you need to change line 318 of snapchat_agent.php with the full path : curl_setopt($ch, CURLOPT_CAINFO, '/full/path/to/file/ca_bundle.crt');