Facebook图形V2.12:总是发送相同数量的fan_count

时间:2018-04-24 04:05:11

标签: facebook facebook-graph-api

我尝试了一些脚本(从头开始https调用或库),我总是在fan_count不会改变的情况下。 用浏览器就可以了 与邮递员一起,fan_count号码不会改变。 使用脚本(从头开始或使用库),nodejs,php等。它也没有改变:

我的要求是: https://graph.facebook.com/v2.12/663065333785499?access_token=MY_ACCESS_TOKEN&fields=fan_count

你现在有任何工作方式吗?

我放了两个目的相同的脚本: 获取我的Facebook商家页面的fan_count号码。 问题完全相同:即使您喜欢或不喜欢有关的facevook商业页面,fan_count号码仍会被阻止在给定值。第一个是“从头开始”(nodejs)。 secund使用PHP库(参见脚本)

我只想获得一个技术解决方案来获取facebook商业页面的fan_count号码(V2.12)。我真的不关心语言库,它必须有效。

2个脚本示例:

如果使用另一个库(php):“facebook / graph-sdk”:“^ 5.6”

<?php
require_once __DIR__ . '/vendor/autoload.php'; // change path as needed

$fb = new \Facebook\Facebook([
    'app_id' => '__APP_ID__',
    'app_secret' => '__APP_SECRET__',
    'default_graph_version' => 'v2.12',
    //'default_access_token' => '{access-token}', // optional
]);

// Use one of the helper classes to get a Facebook\Authentication\AccessToken entity.
//   $helper = $fb->getRedirectLoginHelper();
//   $helper = $fb->getJavaScriptHelper();
//   $helper = $fb->getCanvasHelper();
//   $helper = $fb->getPageTabHelper();

try {
    // Get the \Facebook\GraphNodes\GraphUser object for the current user.
    // If you provided a 'default_access_token', the '{access-token}' is optional.
    //$fb->getApp()->getId().'|'.$fb->getApp()->getSecret()
    $response = $fb->get('/663065333785499?fields=fan_count', $fb->getApp()->getAccessToken()->getValue());
} catch(\Facebook\Exceptions\FacebookResponseException $e) {
    // When Graph returns an error
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch(\Facebook\Exceptions\FacebookSDKException $e) {
    // When validation fails or other local issues
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
}

die(var_dump($response));
nodejs中的另一个脚本
var express = require('express');
var cookieSession = require('cookie-session');
var setCookie = require('set-cookie-parser');


var app = express();
app.use(cookieSession({
    name: 'session',
    keys: [/* secret keys */],

    // Cookie Options
    maxAge: 24 * 60 * 60 * 1000 // 24 hours
}))

const https = require('https');

var host = 'graph.facebook.com';
var path = '/v2.12/663065333785499?access_token=__ACCESS_TOKEN__&fields=fan_count';
var headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
    'Content-Type' : 'application/x-www-form-urlencoded',
    'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
    'Accept-encoding': 'gzip, deflate, br',
    'Accept-language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7,ro;q=0.6',
    'Connection': 'keep-alive',
    'Upgrade-insecure-requests': 1,
};

var optionsget = {
    headers: headers,
    host: host,
    path: path,
    method: 'GET'
};


https.get(optionsget, (res) => {

    var cookies = setCookie.parse(res, {
        decodeValues: true  // default: true
    });

    res.on('data', (d) => {
        process.stdout.write(d);
    });

}).on('error', (e) => {
    console.error(e);
});

2 个答案:

答案 0 :(得分:0)

var express = require('express');
var cookieSession = require('cookie-session');
var setCookie = require('set-cookie-parser');


var app = express();
app.use(cookieSession({
    name: 'session',
    keys: [/* secret keys */],

    // Cookie Options
    maxAge: 24 * 60 * 60 * 1000 // 24 hours
}))

const https = require('https');

var host = 'graph.facebook.com';
var path = '/v2.12/663065333785499?access_token=__ACCESS_TOKEN__&fields=fan_count';
var headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
    'Content-Type' : 'application/x-www-form-urlencoded',
    'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
    'Accept-encoding': 'gzip, deflate, br',
    'Accept-language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7,ro;q=0.6',
    'Connection': 'keep-alive',
    'Upgrade-insecure-requests': 1,
};

var optionsget = {
    headers: headers,
    host: host,
    path: path,
    method: 'GET'
};


https.get(optionsget, (res) => {

    var cookies = setCookie.parse(res, {
        decodeValues: true  // default: true
    });

    res.on('data', (d) => {
        process.stdout.write(d);
    });

}).on('error', (e) => {
    console.error(e);
});

答案 1 :(得分:0)

如果使用另一个库(php):“facebook / graph-sdk”:“^ 5.6”

<?php
require_once __DIR__ . '/vendor/autoload.php'; // change path as needed

$fb = new \Facebook\Facebook([
    'app_id' => '__APP_ID__',
    'app_secret' => '__APP_SECRET__',
    'default_graph_version' => 'v2.12',
    //'default_access_token' => '{access-token}', // optional
]);

// Use one of the helper classes to get a Facebook\Authentication\AccessToken entity.
//   $helper = $fb->getRedirectLoginHelper();
//   $helper = $fb->getJavaScriptHelper();
//   $helper = $fb->getCanvasHelper();
//   $helper = $fb->getPageTabHelper();

try {
    // Get the \Facebook\GraphNodes\GraphUser object for the current user.
    // If you provided a 'default_access_token', the '{access-token}' is optional.
    //$fb->getApp()->getId().'|'.$fb->getApp()->getSecret()
    $response = $fb->get('/663065333785499?fields=fan_count', $fb->getApp()->getAccessToken()->getValue());
} catch(\Facebook\Exceptions\FacebookResponseException $e) {
    // When Graph returns an error
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch(\Facebook\Exceptions\FacebookSDKException $e) {
    // When validation fails or other local issues
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
}

die(var_dump($response));