如何使用htc sense api在facebook上发布

时间:2015-12-08 08:01:04

标签: facebook api facebook-graph-api

我正在使用带有HTC Sense Token的Facebook SDK,所以我想用用户身份验证执行该请求,只需使用令牌做这样的令牌,我想使用app发送请求(使用htc感知令牌)i有一个appid但我没有秘密的代码在Facebook上发布如何获得应用程序HTC感应应用密码发布在我的墙上,页面等

    <?php
    session_start();

    require_once 'facebook-php-sdk/autoload.php';
    use Facebook\FacebookSession;
    use Facebook\FacebookRequest;
    use Facebook\GraphUser;
    use Facebook\FacebookRequestException;
    use Facebook\FacebookRedirectLoginHelper;

    $api_key = 'FACEBOOK_APP_ID';
    $api_secret = 'FACEBOOK_APP_SECRET';
    $redirect_login_url = 'http://www.yoursite.com/somefolder/file.php';
/ initialize your app using your key and secret
FacebookSession::setDefaultApplication($api_key, $api_secret);

// create a helper opject which is needed to create a login URL
// the $redirect_login_url is the page a visitor will come to after login
$helper = new FacebookRedirectLoginHelper( $redirect_login_url);

// First check if this is an existing PHP session
if ( isset( $_SESSION ) && isset( $_SESSION['fb_token'] ) ) {
    // create new session from the existing PHP sesson
    $session = new FacebookSession( $_SESSION['fb_token'] );
    try {
        // validate the access_token to make sure it's still valid
        if ( !$session->validate() ) $session = null;
    } catch ( Exception $e ) {
        // catch any exceptions and set the sesson null
        $session = null;
        echo 'No session: '.$e->getMessage();
    }
}  elseif ( empty( $session ) ) {
    // the session is empty, we create a new one
    try {
        // the visitor is redirected from the login, let's pickup the session
        $session = $helper->getSessionFromRedirect();
    } catch( FacebookRequestException $e ) {
        // Facebook has returned an error
        echo 'Facebook (session) request error: '.$e->getMessage();
    } catch( Exception $e ) {
        // Any other error
        echo 'Other (session) request error: '.$e->getMessage();
    }
}
if ( isset( $session ) ) {
    // store the session token into a PHP session
    $_SESSION['fb_token'] = $session->getToken();
    // and create a new Facebook session using the cururent token 
    // or from the new token we got after login
    $session = new FacebookSession( $session->getToken() );
    try {
        // with this session I will post a message to my own timeline
        $request = new FacebookRequest(
            $session, 
            'POST', 
            '/me/feed', 
            array(
                'link' => 'www.finalwebsites.com/facebook-api-php-tutorial/',
                'message' => 'A step by step tutorial on how to use Facebook PHP SDK v4.0'
            )
        );
        $response = $request->execute();
        $graphObject = $response->getGraphObject();
        // the POST response object 
        echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';
        $msgid = $graphObject->getProperty('id');
    } catch ( FacebookRequestException $e ) {
        // show any error for this facebook request
        echo 'Facebook (post) request error: '.$e->getMessage();
    }
    if ( isset ( $msgid ) ) {
        // we only need to the sec. part of this ID
        $parts = explode('_', $msgid);
        try {
            $request2 = new FacebookRequest(
                $session,
                'GET',
                '/'.$parts[1]
            );
            $response2 = $request2->execute();
            $graphObject2 = $response2->getGraphObject();
            // the GET response object
            echo '<pre>' . print_r( $graphObject2, 1 ) . '</pre>';
        } catch ( FacebookRequestException $e ) {
            // show any error for this facebook request
            echo 'Facebook (get) request error: '.$e->getMessage();
        }
    }
} else {
    // we need to create a new session, provide a login link
    echo 'No session, please <a href="'. $helper->getLoginUrl( array( 'publish_actions' ) ).'">login</a>.';
}

1 个答案:

答案 0 :(得分:0)

您需要使用自己应用的令牌。不确定为什么你想使用HTC Sense App的令牌发布,afaik它只用于发送垃圾邮件 - 因为很多权限已经被批准了。不要这样做,为自己的应用创建自己的授权流程:https://developers.facebook.com/docs/facebook-login

...然后使用其他权限进行登录审核:https://developers.facebook.com/docs/facebook-login/review

尝试使用/滥用/劫持另一个应用程序是错误的,绝对不允许。