0

我需要从我的 php 网站分享一个页面到用户的 facebook 墙。如果用户未登录 facebook,我的网站使用重定向到 facebook 登录页面

    $user = $facebook->getUser();
    if($user) {
        $result = $facebook->api(
            '/me/feed/',
            'POST',
            array('access_token' => $this->access_token, 'link'=>'google.com', 'message' => 'Test link')
        );
        $this->Session->setFlash('Your link has been succesfully posted on your wall');
        $this->redirect($this->referer());
    }else {
       $login_url_params = array(
          'req_perms' => 'publish_stream',
          'redirect_uri' => 'localhost/pictrail' //thts the same path I gave to my facebook app
       );
       $login_url = $facebook->getLoginUrl($login_url_params);
       header("Location: {$login_url}");
       exit();
    }

因此,当用户未登录 facebook 时,它会重定向到 facebook 以供用户登录,然后无论我输入的网址如何,它都会重定向到 localhost/pictrail。我想将其重定向为 localhost/pictrail/images/param ...我该如何实现呢?我尝试了“localhost/pictrail/images/99”,但没有成功。用户登录 facebook 后一切正常。

4

1 回答 1

0

You cannot redirect from Facebook to localhost as it's not a valid address.

The way that I got around this, for development, was to edit my hosts file and replace the domain with my local ip.

www.example.com 127.0.0.1

Then you can redirect to www.example.com from your Facebook app and it will render your local development version.

Be sure to add this domain to your local server's vhost or similar.


Sorry I misread your question. To change the Facebook redirect url you need to change it in your Facebook app. So you'd have to pass a custom field through to Facebook and then tack it back on afterwards.

Have a look through this, https://developers.facebook.com/docs/authentication/server-side/

于 2012-07-27T09:54:29.890 回答