Question

Hello I have all sorts of tutorials for authenticating with oAuth, but it seems like everyone else has one piece of the puzzle that I don't.

In my CMS I am editing the controller, where info gets processed on the submit button. $_POST contains this data and is simply evaluated for content

if(!empty($_POST))
        {
            $mingurl = 'http://www.myurl.com';
            $mingmsg = "New tweet! Link: " . $mingurl;

            //Connect to Twitter
            $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET);

            $connection->getAuthorizeURL(OAUTH_TOKEN, true);

            // Posten
            $connection->post('statuses/update', array('status' => $mingmsg));

            // Error afhandeling
            $httpc = $connection->http_code;
            if($httpc == 200) {
                echo 'Tweet posted!';
            } else {
                echo "Failed!";
            } 

        }

Now it seems that nothing happened, especially given that the twitter account is not updated. I notice that nowhere here do I call other twitteroauth functions, such as the one that should initially login and allow the twitter application to edit things, but NO tutorial details how this should work. What functions should I call, I am using Abraham Williams twitter oauth php object.

Also I'm not sure if I need to edit the model or view just to add these behind the scenes updating, but I wonder about the popup to add your twitter credentials the first time, would this need to be a feature of the view? How would I call that from the controller etc

Was it helpful?

Solution

I think you should first get the request token and then actually use the authorize URL for the authentication.

$request_token = $connection->getRequestToken($callback_url);

$url = $connection->getAuthorizeURL($token);
header('Location: '.$url); 

I can't remember why exactly but for some reason I could use the library you are using right now and created my own: http://code.google.com/p/social-php/

You could also consider to use the 'standard' tweet button if that is more suitable: http://twitter.com/about/resources/tweetbutton

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top