Trouble using API to initiate a Twitter payment

1 view
Skip to first unread message

blakechesney

unread,
May 9, 2009, 9:03:32 PM5/9/09
to Tipjoy Developers
I've been trying to work with the Tipjoy API all day. I first tried it
in Python but was struggling greatly so I tried moving to PHP. I am
currently trying to initiate a Twitter payment, but when I send my
form, it results in a failure for reason "must HTTP POST". I do not
understand why this occurs, as it seems I am doing a POST, for my
form's method is post, and whenever I access the form data, I use
$_POST. Here is the code I have:

<?php
if ($_POST['submitBtn1']) {

header("Location:http://tipjoy.com/api/tweetpayment?twitter_username=".
$_POST['username']."&twitter_password=".$_POST['password']);

}
else {
?>

<form name="cred" method="post" action="<?=$_SERVER['PHP_SELF']?>">
Twitter Username: <input type="text" name="username"><br />
Twitter Password: <input type="password" name="password"><br />
<input type="submit" name="submitBtn1" value="tweetpayment">
</form>

<?php } ?>

I am also confused as to why this is not working, because I have
another page that contains the EXACT same code, except instead of
"http://tipjoy.com/api/tweetpayment" after "Location:", "http://
tipjoy.com/api/user/balance" is there; when I submit the form for this
other page, it works fine (I am prompted to open a JSON file and I can
see the result).

Any clues are helpful.
Thank you.
Blake

Ivan Kirigin

unread,
May 9, 2009, 9:08:49 PM5/9/09
to tipjoy-d...@googlegroups.com
I don't know PHP (hopefully some who does can chime in).

But, it looks like you're POSTing your form to your server side but
then just parsing the parameters into a GET request, and sending the
user there.

For an example of using PHP to post an external API, perhaps you can
look at the resources for using PHP to work with the twitter API
http://apiwiki.twitter.com/Libraries#PHP

There should be some good examples there.

The authorization for Tipjoy's API is different (twitter uses HTTP
basic auth, and we ask for credentials as parameters), but the rest
should be very similar.

Ivan
http://tipjoy.com

Blake

unread,
May 10, 2009, 12:48:54 AM5/10/09
to Tipjoy Developers
I really couldn't understand or find anything that seemed useful
there; I'm sorry. :-(

I've tried several other methods of redirecting the user, first
messing around with urlencode() and then fopen(). Neither helped.

On May 9, 7:08 pm, Ivan Kirigin <ivan.kiri...@gmail.com> wrote:
> I don't know PHP (hopefully some who does can chime in).
>
> But, it looks like you're POSTing your form to your server side but
> then just parsing the parameters into a GET request, and sending the
> user there.
>
> For an example of using PHP to post an external API, perhaps you can
> look at the resources for using PHP to work with the twitter APIhttp://apiwiki.twitter.com/Libraries#PHP
>
> There should be some good examples there.
>
> The authorization for Tipjoy's API is different (twitter uses HTTP
> basic auth, and we ask for credentials as parameters), but the rest
> should be very similar.
>
> Ivanhttp://tipjoy.com

Ivan Kirigin

unread,
May 10, 2009, 1:22:19 PM5/10/09
to tipjoy-d...@googlegroups.com
You aren't supposed to redirect the user. Your server side needs to
POST to Tipjoy, and then you parse the results.

Look at this code for http://tatatweet.com

It doesn't redirect the user. It contacts TIpjoy
http://github.com/ikirigin/tatatweet/blob/debf0037863e1cdc9e0de68b5391b7daa49b16db/tipjoy/models.py#L92

Ivan
http://tipjoy.com

Blake

unread,
May 10, 2009, 4:04:56 PM5/10/09
to Tipjoy Developers
Oh, okay. I think I understand that, now. I will look over the link
you gave me and see if I can find anything useful from it.

So, is JSON what parses the results? Is it the only format I can use
to get the result I want?

On May 10, 11:22 am, Ivan Kirigin <ivan.kiri...@gmail.com> wrote:
> You aren't supposed to redirect the user. Your server side needs to
> POST to Tipjoy, and then you parse the results.
>
> Look at this code forhttp://tatatweet.com
>
> It doesn't redirect the user. It contacts TIpjoyhttp://github.com/ikirigin/tatatweet/blob/debf0037863e1cdc9e0de68b539...
>
> Ivanhttp://tipjoy.com

Ivan Kirigin

unread,
May 11, 2009, 8:11:27 AM5/11/09
to tipjoy-d...@googlegroups.com
json is currently the only return format for most Tipjoy API endpoints.

There are free json parsers available in every language.

Ivan
http://tipjoy.com
Reply all
Reply to author
Forward
0 new messages