Skip to content
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

Can't get snap to send! #63

Closed
DanMossa opened this issue Dec 25, 2014 · 58 comments
Closed

Can't get snap to send! #63

DanMossa opened this issue Dec 25, 2014 · 58 comments

Comments

@DanMossa
Copy link

<?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
Copy link
Collaborator

hako commented Dec 25, 2014

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

@DanMossa
Copy link
Author

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
Copy link

Mxchael commented Dec 26, 2014

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

@DanMossa
Copy link
Author

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

@hako
Copy link
Collaborator

hako commented Dec 26, 2014

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

@hako
Copy link
Collaborator

hako commented Dec 26, 2014

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

@DanMossa
Copy link
Author

@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
Copy link

Snowlav commented Dec 27, 2014

@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
Copy link
Author

@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
Copy link

Snowlav commented Dec 27, 2014

"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
Copy link
Author

@Snowlav Lol i wish it was that easy :(

@DanMossa
Copy link
Author

Uh any ideas guys ?:O

@KyleBoyer
Copy link

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
Copy link
Author

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

@liamjack
Copy link

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

  • data : Encrypted image data
  • media_id : Username in capitals and a random media ID
  • type : Media type
  • username
  • req_token
  • timestamp
  • features_map : {}

Response

No content.

@DanMossa
Copy link
Author

DanMossa commented Jan 2, 2015

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

@liamjack
Copy link

liamjack commented Jan 2, 2015

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
#63 (comment).

@KyleBoyer
Copy link

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
Copy link

liamjack commented Jan 3, 2015

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

@DanMossa
Copy link
Author

DanMossa commented Jan 3, 2015

@cuonic Page not found :O

@liamjack
Copy link

liamjack commented Jan 3, 2015

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

@DanMossa
Copy link
Author

DanMossa commented Jan 3, 2015

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

@liamjack
Copy link

liamjack commented Jan 3, 2015

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

@DanMossa
Copy link
Author

DanMossa commented Jan 3, 2015

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

@DanMossa
Copy link
Author

DanMossa commented Jan 3, 2015

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

@liamjack
Copy link

liamjack commented Jan 3, 2015

@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
Copy link
Author

DanMossa commented Jan 3, 2015

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

@liamjack
Copy link

liamjack commented Jan 3, 2015

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
Copy link
Author

DanMossa commented Jan 3, 2015

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

@liamjack
Copy link

liamjack commented Jan 3, 2015

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
Copy link
Author

DanMossa commented Jan 3, 2015

@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
Copy link

liamjack commented Jan 3, 2015

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
Copy link
Author

DanMossa commented Jan 3, 2015

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
Copy link

liamjack commented Jan 3, 2015

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

@DanMossa
Copy link
Author

DanMossa commented Jan 3, 2015

@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
Copy link

liamjack commented Jan 3, 2015

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

@liamjack
Copy link

liamjack commented Jan 3, 2015

What browser are you using ? What web server ?

@DanMossa
Copy link
Author

DanMossa commented Jan 3, 2015

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

@liamjack
Copy link

liamjack commented Jan 3, 2015

Try running it locally with a WAMP / LAMP server

@DanMossa
Copy link
Author

DanMossa commented Jan 3, 2015

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
Copy link

liamjack commented Jan 3, 2015

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
Copy link
Author

DanMossa commented Jan 3, 2015

@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
Copy link

liamjack commented Jan 3, 2015

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

@DanMossa
Copy link
Author

DanMossa commented Jan 3, 2015

Still get the same No Authentication Details =/

Just want to say thank you so much btw

@DanMossa
Copy link
Author

DanMossa commented Jan 3, 2015

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

@liamjack
Copy link

liamjack commented Jan 3, 2015

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
Copy link
Author

DanMossa commented Jan 3, 2015

@liamjack
Copy link

liamjack commented Jan 3, 2015

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

@DanMossa
Copy link
Author

DanMossa commented Jan 3, 2015

@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
Copy link

liamjack commented Jan 3, 2015

@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');

@liamjack
Copy link

liamjack commented Jan 3, 2015

Try the following line actually : curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/ca_bundle.crt');

@DanMossa
Copy link
Author

DanMossa commented Jan 4, 2015

@cuonic http://i.imgur.com/AtMMrBB.png

@liamjack
Copy link

liamjack commented Jan 4, 2015

@Dgameman1 Ok well that's a good start, login was successful via the new endpoint. You can remove the var_dump($login); stuff now. Is that the upload endpoint displaying the UNSUPPORTED MEDIA TYPE error ? Are you definitely uploading a JPEG image, relatively small ?

@KyleBoyer
Copy link

@cuonic Using this new endpoint, I've been able to send people images, just not post them to the story now... Is there a new endpoint for posting stories?

@liamjack
Copy link

liamjack commented Jan 4, 2015

@KyleBoyer : Watching the Android application's network traffic when posting a story it doesn't seem to use /ph/upload - it skips that step and does an "all-in-one" request with /bq/retry_post_story

@DanMossa
Copy link
Author

DanMossa commented Jan 5, 2015

@cuonic You are god's gift to man kind. Thank you so much. But now how do you suggest we fix the post while refreshing when it's hosted up online?

EDIT: I got everything to work. ILY

@liamjack
Copy link

liamjack commented Jan 5, 2015

@Dgameman1 Glad you got everything working, happy to help :)

@DanMossa DanMossa closed this as completed Jan 5, 2015
@KyleBoyer
Copy link

@cuonic @Dgameman1 How to you getSnaps using the new API? Is it hidden in the conversations_response?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants