0

I"m trying to post data to a server from objective C and I am trying to get a JSON returned in it.

I am looking at the Snaphax API for PHP and Snaphaxpy API and trying to rewrite it from PHP into Objective C. The links for the code are: https://github.com/tlack/snaphax https://github.com/jasonanovak/snaphaxpy/blob/master/snaphaxpy.py

I'm also especially looking at: http://adamcaudill.com/2012/06/16/snapchat-api-and-security/ but apparently this is outdated

My code is:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://feelinsonice.appspot.com/ph/login"]];
    [request setHTTPMethod:@"POST"];
    [request addValue:@"******testusername******" forHTTPHeaderField:@"username"];
    [request addValue:@"*********" forHTTPHeaderField:@"password"];
    [request addValue:@"M02cnQ51Ji97vwT4" forHTTPHeaderField:@"blob_enc_key"];
    [request addValue:@"false" forHTTPHeaderField:@"debug"];
    [request addValue:@"iEk21fuwZApXlz93750dmW22pw389dPwOk" forHTTPHeaderField:@"secret"];
    [request addValue:@"m198sOkJEn37DjqZ32lpRu76xmw288xSQ9" forHTTPHeaderField:@"static_token"];
    [request addValue:@"Snaphax 4.0.1 (iPad; iPhone OS 6.0; en_US)" forHTTPHeaderField:@"user_agent"];
    [request addValue:@"930cf95a6731dc986ef3bceef6abbaf420e94d8d197dca87b9b47314d8c51b3b" forHTTPHeaderField:@"req_token"];
    [request addValue:@"1355776346532" forHTTPHeaderField:@"timestamp"];


    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];        
    NSString *dataString = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

    NSLog(@"%@", dataString);

I haven't included a real username/password. How come, however, does this not work as I have literally copied everything I have found and implemented in a new language...

Am I not POSTing the data correctly? I tried using ASIHTTPRequest but I couldn't get that working either...

Any suggestions or ideas based on experience??

Bhanu
  • 1,249
  • 10
  • 17
falky
  • 589
  • 2
  • 11
  • 27

2 Answers2

2

Check my answer here: how can I use NSURLConnection Asynchronously?

You can send a POST request by using

HTTPCachedController *ctrl = [[[HTTPCachedController alloc] initWithRequestType:1 andDelegate:self] autorelease];
[ctrl postRequestToURL:@"https://feelinsonice.appspot.com/ph/login" withData:@"username=user1&password=pass& ... "];

Source code of the HTTPCachedController can be found here: HTTPCachedController

Community
  • 1
  • 1
Vame
  • 2,033
  • 2
  • 18
  • 29
  • Really good. Cheers! Still need to try and connect it though but that is much better now thankyou! :) – falky Jul 05 '13 at 14:58
0

If you are looking for updated endpoints and whatnot, I wrote a quick Python script that you should be able to read through for some endpoints and the parameters they require. Some of the endpoints are as follow:

Shameless Plug: I'm hosting a wrapper for the Snapchat API right now so you don't have to implement encryption into your project and you can safe time and your project can be more efficient. Check it out here!

You will also notice a lot of strange abbreviations in the JSON (like Adam said, Snapchat's API wasn't really built for human consumption), so I've gone ahead and mapped that out for you:

ID: id
Snap ID: c_id
Media Type: m = 0 (pic), 1 (video)
Sent Timestamp: sts
Opened Timestamp: ts
Sender: sn
Recipient: rp
Status: st = 1 (sent to you), 2 (sent by you)
Time: t
Screenshot Count: c

Note: I will be updating that repo with some new code within the next month or so. Also, the most up-to-date endpoints often vary between /ph/ and /bq/ for different requests for some reason, so don't accidentally use one when you meant to use the other.

Graham Smith
  • 2,125
  • 2
  • 13
  • 12