开发者

Problem with the redirection: Twitter API Oauth

开发者 https://www.devze.com 2023-01-04 06:55 出处:网络
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):

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("Loc开发者_开发百科ation: $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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号