Facebook API: How to publish to Page feed while user is offline without offline_access permission

前端 未结 3 1659
旧巷少年郎
旧巷少年郎 2021-02-02 00:01

Using Facebook\'s Graph API, I\'ve been successful at publishing to a user\'s feed while the user is offline with only the publish_stream permission. I don\'t need the offline_

3条回答
  •  抹茶落季
    2021-02-02 00:23

    This is my answer. Above code does not work for me. But I made one for myself, that works perfectly. Here is the code.

    Code for server side:

     YOUR_APP_ID,
        'secret' => YOUR_APP_SECRET,
    ));
    
    if($_SESSION['access_token']!='') {
        $access_token = $_SESSION['access_token'];
    $user_id = $_SESSION['user_id'];
    } else {
        $access_token = $_REQUEST['access_token'];
        $_SESSION['access_token'] = $_REQUEST['access_token'];
        $user_id = $_REQUEST['user_id'];
        $_SESSION['user_id'] = $_REQUEST['user_id'];
    }
    
    $user_id = $_REQUEST['user_id'];
    
    $facebook->setAccessToken($_REQUEST['access_token']);
    
    $post =  array(
        'message' => 'This message is posted with access token - ' . date('Y-m-d H:i:s')
    );
    
    // and make the request
    $response = $facebook->api('/me/feed', 'POST', $post);
    ?>
    

    Code for client side:

     YOUR_APP_ID,
        'secret' => YOUR_APP_SECRET,
    ));
    
    $user = $facebook->getUser();
    if ($user) {
        try {
            $user_profile = $facebook->api('/me');
        } catch (FacebookApiException $e) {
            // The access token we have is not valid
            $user = null;
        }
    }
    ?>
    
    Login with Facebook Logout from Facebook Post Into Wall

    Please disable "Remove offline_access permission:" from fb apps advance setting. by selecting disable radio button.

提交回复
热议问题