Shahid Karimi
Shahid Karimi

Reputation: 4357

Facebook application authentication issue

I wrote the following code to authenticate a facebook application but instead of google many days it did not solve. The problem is the when the application is first accessed user is prompt to application authentication dialog. when the user allows application it keeps blinking the url. neither shows dialog nor application. After closing the browser yes it runs fine. please can you find out what is the problem. I will be very thankful.

Code:

$canvas_page = "---my canvas url----"; //i removed actual url here!
// Create our Application instance (replace this with your appId and secret).
   $auth_url = "http://www.facebook.com/dialog/oauth?client_id="
            . $app_id . "&redirect_uri=" . urlencode($canvas_page) ."&scope=email,read_stream";
     $signed_request = $_REQUEST["signed_request"];

     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

     $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

     if (!empty($data["user_id"])) {
         echo 'Hello: '.$data["user_id"];
     }else{
         echo "What is the hell";
          echo("<script> location.href='" . $auth_url . "'</script>");
     }

Upvotes: 0

Views: 589

Answers (2)

user968652
user968652

Reputation:

It should work

 $canvas_page = "---my canvas url----"; //i removed actual url here! // Create our Application instance (replace this with your appId and secret).    $auth_url = "http://www.facebook.com/dialog/oauth?client_id="             . $app_id . "&redirect_uri=" . urlencode($canvas_page) ."&scope=email,read_stream";      $signed_request = $_REQUEST["signed_request"];       list($encoded_sig, $payload) = explode('.', $signed_request, 2);        $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);       if (!empty($data["user_id"])) {          echo 'Hello: '.$data["user_id"];      }else{          echo "What is the hell";           echo("<script> location.href='" . $auth_url . "'</script>");      } 

Upvotes: 2

ifaour
ifaour

Reputation: 38135

use:

echo("<script> top.location.href='" . $auth_url . "'</script>");

With top!

Upvotes: 1

Related Questions