facebook $facebook->getSignedRequest(); error

后端 未结 6 1011
孤城傲影
孤城傲影 2021-01-06 14:39

i am trying to add this script to my iframe app on facebook but it seems not to work:

    $signed_request = $facebook->getSignedRequest();
$like_status =          


        
相关标签:
6条回答
  • 2021-01-06 15:15

    I had similar problem a while ago - the solution was to specify full url for tab or/and canvas page to receive signed request.

    Example: use http://myapp.com/myapp/index.php, isntead of http://myapp.com/myapp/

    0 讨论(0)
  • 2021-01-06 15:25

    $_REQUEST['signed_request'] could be empty if your canvas (or page tab) URL is not the final one and redirects to some other URL because Facebook posts the signed request only once. When redirecting, the posted value is lost.

    If you have some control over the redirection, then add ?signed_request=$_REQUEST['signed_request'] to your redirected URL (you might also need to pass other custom GET parameters)

    0 讨论(0)
  • 2021-01-06 15:26

    Not sure whats wrong here, but here is a basic page that it will work on. Make sure that the latest version of facebook.php and base_facebook.php is in the same directory. You can find the sdk here: https://github.com/facebook/php-sdk Allso remember to put in your app id and secret where you se all the 111111111111111's

    <?php 
    
    require 'facebook.php';
    
    $app_id ="11111111111111111";
    $app_secret = "11111111111111111111111111";
    
    $facebook = new facebook(array(
        'appId' => $app_id,
        'secret' => $app_secret,
        'cookie' => true
    ));
    
    $signed_request = $facebook->getSignedRequest();
    $page_id = $signed_request["page"]["id"];
    $page_admin = $signed_request["page"]["admin"];
    $like_status = $signed_request["page"]["liked"];
    $country = $signed_request["user"]["country"];
    $locale = $signed_request["user"]["locale"];
    
    
    
    ?>
    
    <!DOCTYPE html>  
    <html lang="en">  
        <head>
        <meta charset="utf-8"/>
        <title>untiteled</title>
    
    
        <script type="text/javascript">
            window.fbAsyncInit = function() {
                FB.Canvas.setSize(); 
            }
    
        </script>
    
    
    </head>
    <body>
        <div class="wrapper">
    
            <?php if(!$like_status):?> 
                <div class="likearrow"><div><div></div></div></div>
                <p id="like">Click "<b>like</b>" if you want to become a fan of this app</p>
            <?php endif; ?>
    
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
    
        </div>
    
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <script>
    FB.init({
        appId: '111111111111111111111',
        status: true,
        cookie: true,
        xfbml: true
    
    });
    </script>       
    </body>
    

    0 讨论(0)
  • 2021-01-06 15:28

    Facebook sends the signed request to your page when it is called from facebook.

    So:

    $signed_request = $_REQUEST["signed_request"];
    list($encoded_sig, $payload) = explode('.', $signed_request, 2);
    $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
    
    0 讨论(0)
  • 2021-01-06 15:35

    Unfortunately, I had the same issue. After hours and hours trying to solve it, I finally created a new application, with exactly the same set up. I updated key and secret in my code to the new ones and voilà - its running like a charm from the first attempt.

    Definitly a Facebook issue. Maybe resetting App ID and secret could also had worked, but I didn't try that first.

    0 讨论(0)
  • 2021-01-06 15:37
    • what is the version of facebook php sdk?
    • check access_log and error_log in your web server
    • have you some missing ";" ?
    0 讨论(0)
提交回复
热议问题