tags:

views:

68

answers:

3

Im trying to use the following PHP to add a favorite to my account:

<?php
    if(isset($_POST['submit'])) {
    $fav = $_REQUEST['fav'];
    $connection->post('favorites/create', array('id' => $fav));
    echo "<div style='padding-bottom: 5px; color: #0099FF;'>Fav Created Successfully.</div>";

    }
?>

With the following form:

<form id="fav" method='post' action='index.php'>
    <input type="text" style="width: 346px;" name="fav" id="fav" ></input>
    <input type="submit" value="Fav This!" name="submit" id="submit" />
</form>

Its not creating a favorite, Can anyone spot anything wrong with it?

PS: I am using the OAuth API:

 $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
A: 

When I tried it, it says the following.

This method requires a GET.

Although Twitter API documentation says it requires a POST. So, try to do a GET request on it:

 $response = $connection->get('favorites/create', array('id' => $fav));
 // now print the response to see if any error pops up:
 print_r($response);
shamittomar
This is using Oauth, $connection is the tokens.
danit
@danit, answer updated.
shamittomar
I get [error] => Not authorized using a get
danit
And what error do you get using `print_r($response)` when you use a POST ?
shamittomar
A: 

If I'm not mistaken, you don't need to add an "id" parameter.

Looking at Twitter's Documentation the URL to create a favorite would be http://api.twitter.com/1/favorites/create/12345.xml where "12345" is the ID of the tweet.

Mark B.
He's doing that by `array('id' => $fav)`.
shamittomar
I was getting the ID but constructing the URL incorrectly.
danit
A: 
$response = $connection->post('favorites/create/'.$fav);

The ID is not a parameter.

danit