简体   繁体   中英

Facebook PHP SDK getSignedRequest() returns null when script called with Fetch API

I am using Facebook Web SDKs. I am using v5 PHP SDK, so I check if user is logged in with calling getSignedRequest(). The problem is, that when the user is logged in and I call script directly in web browser, it successfully finds out user is logged in, but when I call script with Fetch Api, the getSignedRequest() returns null. The code looks like this

    $fb = new Facebook([
        'app_id' => {app_id},
        'app_secret' => {app_secret},
    ])
    $helper = $fb->getJavaScriptHelper();

    $sr = $helper->getSignedRequest();

    if(!$sr){
        var_dump('not logged in');
    } else{
        var_dump($sr->getUserId());
    }

As I said, when this is called manually by calling the url in web browser, it returns user id of logged in user. But when the url is called with Fetch Api, getSignedRequest() returns null and 'not logged in' string is dumped. When I call FB.getLoginStatus() in js before Fetching url, it says user is "connected". Can´t really figure out what could be causing the problem.

Solved: Fetch isn´t by default sending cookies that are necessary for user identification.

Problem solved. Fetch isn´t by default sending cookies that are necessary for user identification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM