字面上只是工作,我不知道我做错了什么 - javascript / php / facebook sdk

时间:2014-08-10 02:36:25

标签: javascript php facebook facebook-graph-api curl

我确实只是有这个工作,移动文件夹,并没有工作。我搬回来了,它还没有用。它不再发布到我的Facebook页面了!帮助我搞砸了什么?!?!?!我有facebook.php和generatePageToken.php。 facebook.php调用生成。这是facebook.php

<!doctype html>
<html>
<head>
        <script type="text/javascript">

        function SendToFacebook()
        {
            window.fbAsyncInit = function () {
                // init the FB JS SDK
                FB.init({
                    appId: '432036336937975',                        // App ID from the app dashboard
                    status: false,                                 // Check Facebook Login status
                    xfbml: true                                  // Look for social plugins on the page
                });


                FB.login(function (response) {
                    FB.api('/me/accounts', function (apiresponse) {
if (response.authResponse) {
        //simple user access token
        var accessToken = response.authResponse.accessToken,
            ajaxRequest = new XMLHttpRequest(),
            pageId = '1521533601413118';

        ajaxRequest.onreadystatechange = function() {
            if(ajaxRequest.readyState === 4) {
                //print out the extended page access token
                console.log(ajaxRequest.responseText);
            }
        };
        ajaxRequest.open('POST','generatePageToken.php?pageId=' + pageId, true);
        ajaxRequest.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        ajaxRequest.send('accessToken=' + accessToken);
    }




                    });

                }, { scope: 'manage_pages, publish_stream'});

            };
            // Load the SDK asynchronously
            (function (d, s, id) {
                var js, fjs = d.getElementsByTagName(s)[0];
                if (d.getElementById(id)) { return; }
                js = d.createElement(s); js.id = id;
                js.src = "//connect.facebook.net/en_US/all.js";
                fjs.parentNode.insertBefore(js, fjs);
            } (document, 'script', 'facebook-jssdk'));
        }
        </script>

</head>
<body>
<a href="#" onclick="SendToFacebook();">Submit</a>
<div id="fb-root"></div>

</body>
</html>

这是generatePageToken.php

<?php
$accessToken = $_POST['accessToken'];
$pageId = $_GET['pageId'];
$fbAppId = '432036336937975';
$fbAppSecret = '121f0206bdd01dd6a6248d031237be7e';


$appsecretProof = hash_hmac('sha256', $accessToken, $fbAppSecret);
//init curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'facebook-php-3.2');

//get extended user access token
$url = 'https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token' .
    '&client_id=' . $fbAppId .
    '&client_secret=' . $fbAppSecret .
    '&fb_exchange_token=' . $accessToken .
    '&appsecret_proof=' . $appsecretProof;
curl_setopt($ch, CURLOPT_URL, $url);
$curlResult = curl_exec($ch);
$response_params = array();
parse_str($curlResult, $response_params);
$extendedUserToken = $response_params['access_token'];

$appsecretProof = hash_hmac('sha256', $extendedUserToken, $fbAppSecret);


//get extended page access token
$url = 'https://graph.facebook.com/' . $pageId .
    '?fields=access_token' .
    '&access_token=' . $extendedUserToken .
    '&appsecret_proof=' . $appsecretProof;
curl_setopt($ch, CURLOPT_URL, $url);
$curlResult = curl_exec($ch);
curl_close($ch);
//$pageToken = json_decode($curlResult)->access_token;
//PAGE TOKEN NEVER EXPIRES
$pageToken = 'CAAGI70xkqZCcBAKzIhcnPRemwZCQ0zKdFtq5N0gTMmr54u9UECZA2WjoCUUrA4owy5FohSce0MCqPT7ouS8tqud5Ilhk1H1OxozucxTl4MxZBVZCM9ABjZB02xZC2G3ZBSaywwI8zoi7GiNiXf1E7C60xPZBTjP4VbqOOZCixPLdSlMCWQIUSdwvKYqCIpJ5qtWNWThGbDzZAtSW22vZBmiKoiTo';

//ACCESS TOKEN SHOULD NEVER EXPIRE
$data = http_build_query(array(
    'access_token'  => 'CAAGI70xkqZCcBAGdXju1tKsvF6qpwc0AxqC9GbuwSd4DwQYYybvFfPNIvjodz9H1LEknPlUdRcSI8V3ZCBip1RSyNkJ8jA10NVZAvd5sLDsBH0cqYIuX6SCWt7lUWYWaPH3g12pc9rd74W3EUZB1qK4X7qa3ZCHH3eDGjL773CbZAhXXaGLbzhKcvBlk5dYEHjQC50YnoT7IOxKi2nt2HT',
    'message'       => 'hello world!'
));
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v2.1/1521533601413118/feed');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
curl_close($ch);

echo $pageToken;
?>

0 个答案:

没有答案