views:

318

answers:

3

Hello everyone,

I'm testing the twitter API (with OAuth) and I have a little problem, I wonder if anyone knows how to fix it, the situation is that at the time I do this (in my redirect.php):

$ Url = $ connection-> getAuthorizeURL ($ token);
header ("Location: $ url");

The request go to twitter, and it's authenticated, but I this return my application back to the home page, and I want to do it in the page I'm doing the OAuth.

Does anyone know the solution?

In short, when users log in, I want the application return it to the same page, not the beginning.

Ah! When I do the log out, all is correct... because I do this (in my clearsessions.php):

session_start();
session_destroy();
$redireccion = $_SERVER['HTTP_REFERER'];
header("Location: $redireccion");

My problem is in the "log in" :-)

Thanks!

Ehm... You can try it here: http://www.joanballestermoragues.com/oauth/test.php As you can see, the login in twitter redirect to http://www.joanballestermoragues.com/oauth/ and I want to redirect to: http://www.joanballestermoragues.com/oauth/test.php

PS: Ah, any can say... "make an index.php and that's all", but no, because this is for another application, it's only a test and I need to do it in another pages than "index" :-)

Thanks again

+3  A: 

You could set your callback URL in your Twitter connection settings and that should fix it. Otherwise, make sure you set the oauth_callback value when requesting the token before you redirect the user to Twitter.

thekaido
Is dynamic... ;-)In this example is "test.php" but this will be dynamic!
joanballester
Did you set the oauth_callback value when requesting the token before you redirected the user to Twitter? Do you have the settings on twitter correct (eg browser for application mode, and a non-blank default value for Callback URL)?
thekaido
I don't understand your first question, but I think no (how can I do this?). The second one: Browser and non-blank default value for callback. Yes I have this OK. I'm going to write the code that you have mention
joanballester
All correct. I've done! Thanks man :-)
joanballester
A: 

Any ideas?

I need that when twitter makes the callback, this callback can be dynamic in order of the page that the user makes the login will be the callback

Please! :-)

joanballester
A: 

In the class TwitterOAuth, I've seen this construct:

  function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
    $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
    $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
    if (!empty($oauth_token) && !empty($oauth_token_secret)) {
      $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
    } else {
      $this->token = NULL;
    }
  }

And, this line:

$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);

The method OAuthConsumer() can have another parameter, "$callback_url" (default value is NULL).

May be the solution? I can pass another parameter in this moment. I can put the actual URL... Well I can try it later.

joanballester