我正在使用PHP API将旧的FB应用程序迁移到新的图形API
我有两个页面:公共的(不需要用户登录)和私人的(有)
所以我的应用程序中每个php页面的代码如下:
if (this_page_requires_user_login){
$facebook = new Facebook(...) ;
$session = $facebook->getSession ;
if (!$session){
$url =$facebook.getLoginUrl(array(next => current_page );
echo "<fb:redirect url=$url/>" ;
}
// the rest of the code continues here
Run Code Online (Sandbox Code Playgroud)
现在您可以看到,这种工作方式将每个页面转发到登录URL,当它工作时,它也很慢并且将&session = {bla}字符串附加到非常单个URL.
在将用户重定向到登录页面之前,我需要一种方法来检查用户已登录的位置.但我在php api中找不到这样的方法.最好的方法是什么?
编辑
这似乎可以解决问题
if ($session) {
try {
$me = $facebook->api('/me');
if ($me) {
// here comes your code for user who is logged in
}
} catch (FacebookApiException $e) {
login()
}
}else{
login()
}
function login(){ …Run Code Online (Sandbox Code Playgroud) 我设置了一个脚本,允许用户将消息发布到Facebook上的粉丝页面.这一切都有效,但有一个小问题.
问题:
将帖子添加到页面Feed时,它会显示发布用户的个人帐户.我希望它能够显示页面的帐户(例如,当您管理页面时,它说它来自该页面).我发布的帐户拥有该页面的管理员权限,但它仍然显示为个人帖子.
HTTP POST
$url = "https://graph.facebook.com/PAGE_ID/feed";
$fields = array (
'message' => urlencode('Hello World'),
'access_token' => urlencode($access_token)
);
$fields_string = "";
foreach ($fields as $key => $value):
$fields_string .= $key . '=' . $value . '&';
endforeach;
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);
Run Code Online (Sandbox Code Playgroud) 我正试图在Facebook上为一个页面的粉丝获取人口统计数据 - 主要是国家和城市,但年龄和性别是次要的.
执行此操作的主要方法是使用FQL并在洞察表中执行查询.像这样:
FB.api({
method: 'fql.query',
query: "SELECT metric, value FROM insights WHERE object_id='288162265211' AND metric='page_fans_city' AND end_time=end_time_date('2011-04-16') AND period=period('lifetime')"
}, callback);
Run Code Online (Sandbox Code Playgroud)
然而,问题在于该表仅返回最多19条记录,包括国家和城市统计数据.我正在测试的页面的响应是这样的:
[
{
"metric": "page_fans_city",
"value": {
"dallas": "12345",
"atlanta": "12340",
(...)
"miami": "12300"
}
}
]
Run Code Online (Sandbox Code Playgroud)
因此,我想知道是否有任何替代方案 - 获取当前页面粉丝的人口统计信息(无需快照).
我试过的事情:
在查询上使用LIMIT和OFFSET什么都不做(除了有时候,给我一个空列表).
过去讨论的一种替代方法是使用Graph API中的"/ members"方法(此处更多)获取所有用户的列表,然后解析该列表.这根本不起作用 - 一种方法存在,它可能在过去有效,但它不再有效(禁用?).
请求:
https://graph.facebook.com/platform/members?access_token=...
Run Code Online (Sandbox Code Playgroud)
响应:
{"error":
{
"type":"OAuthException",
"message":"(#604) Your statement is not indexable. The WHERE clause must contain an indexable …Run Code Online (Sandbox Code Playgroud) 我正在尝试向用户的帖子发送这样的内容(它最初只显示一个图像,但是当您点击"显示更多"时,您会看到所有五个图像)

我的代码看起来像这样:
NSMutableArray *properties = [[NSMutableArray alloc] initWithCapacity:5];
NSMutableArray *media = [[NSMutableArray alloc] initWithCapacity:5];
for (MyObject *object in self.myObjects) {
[properties addObject:[NSDictionary dictionaryWithObjectsAndKeys:object.name,@"text",
object.link,@"href", nil]];
NSString *imageUrlString = object.url.absoluteString;
[media addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"image",@"type",
imageUrlString,@"src",
object.link,@"href", nil]];
}
NSData *propertyData = [NSJSONSerialization dataWithJSONObject:properties
options:NSJSONWritingPrettyPrinted
error:nil];
NSString *propertiesString = [[NSString alloc] initWithData:propertyData
encoding:NSUTF8StringEncoding];
NSData *mediaData = [NSJSONSerialization dataWithJSONObject:media
options:NSJSONWritingPrettyPrinted
error:nil];
NSString *mediaString = [[NSString alloc] initWithData:mediaData
encoding:NSUTF8StringEncoding];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:myAppID, @"app_id",
link, @"link",
name, @"name",
caption, @"caption",
propertiesString, @"properties",
mediaString, @"media", …Run Code Online (Sandbox Code Playgroud) 我正在使用iOS6模拟器在Xcode 4.5GM上运行Facebook SDK 3.1.我在iOS设置中连接到FB,并使用新的iOS6 FBConnect UI在我的应用程序中成功连接FB.我有一个访问令牌,可以看到我的朋友,发送应用程序请求,发布到我的墙上等.但是,每次我发起任何类型的FBURLConnection,我看到这打印到我的控制台:
Error: HTTP status code: 400
Run Code Online (Sandbox Code Playgroud)
当打印出这个错误时,我进入了FB代码并打印了响应,我得到了:
{
body = {
error = {
code = 100;
message = "(#100) The parameter 'attribution' is required for the 'mobile_app_install' activity";
type = OAuthException;
};
};
code = 400;
}
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?所有功能似乎都有效,但我一直看到这个垃圾邮件我的控制台.
我用最新的Swift3重写我的图形请求.我按照这里的指南 - https://developers.facebook.com/docs/swift/graph.
fileprivate struct UserProfileRequest: GraphRequestProtocol {
struct Response: GraphResponseProtocol {
init(rawResponse: Any?) {
// Decode JSON into other properties
}
}
let graphPath: String = "me"
let parameters: [String: Any]? = ["fields": "email"]
let accessToken: AccessToken? = AccessToken.current
let httpMethod: GraphRequestHTTPMethod = .GET
let apiVersion: GraphAPIVersion = .defaultVersion
}
fileprivate func returnUserData() {
let connection = GraphRequestConnection()
connection.add(UserProfileRequest()) {
(response: HTTPURLResponse?, result: GraphRequestResult<UserProfileRequest.Response>) in
// Process
}
connection.start()
Run Code Online (Sandbox Code Playgroud)
但是,我在connection.add方法中收到此错误:
Type ViewController.UserProfileRequest.Response does not conform to protocol GraphRequestProtocol. …Run Code Online (Sandbox Code Playgroud) 我的网站上有一个艺术家页面,我正在从 facebook 小部件获取特定的艺术家提要。但是我最近将 jQuery 缩小版更新到了最新版本,但它停止工作了。此问题发生在 Firefox Mozilla 上。
我的html
<div class="facebookContent" data-lazy-widget="facebook_1" style="width:100%;text-align:center;">
<div id="facebook_1"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的 jquery 版本
<script src="<?php echo base_url('jquery-3.6.0.min.js?v=' . VERSION); ?>" type="application/javascript"></script>
<script type='application/javascript' src="<?php echo base_url('jquery-ui-1.12.1.min.js?v=' . VERSION); ?>"></script>
<script src="<?php echo base_url('jquery-migrate-1.4.1.min.js?v=' . VERSION); ?>" type="application/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
我的饲料代码
function facefeeddata(){
$('.facebookContent').html("");
setTimeout(function() {
var facebookfeed = $("#facebookfeed").text();
var facebookartist = $("#facebookartist").text();
var container_width = $('.facebookContent').width();
var container_height = $('.facebookContent').height();
$('.facebookContent').html('<div class="fb-page" ' + 'data-href="'+facebookfeed+'"' +' data-width="' + container_width + '" data-height="' + container_height + …Run Code Online (Sandbox Code Playgroud) 我使用Facebook PHP SDK 3.0.1(目前最新).我需要做的是在页面上发布页面的标识.
我尝试将access_token替换为我从页面获取的access_token(/ me/accounts),但现在说令牌由于某种原因无效.Facebook"冒充"页面现在处于离线状态,我没有在API中看到任何关于做我想做的事情的信息......也许我迷路了或者没有找到正确的方向..
这是我修改并用于存档的example.php:
require '../src/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
));
// Get User ID
$user = $facebook->getUser();
//Lists all the applications and pages
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$accounts_list = $facebook->api('/me/accounts');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
$page_selected = 'xxxxxxxxxxxx';
$page_access_token = …Run Code Online (Sandbox Code Playgroud) 我想用Facebook登录实现一个iOS应用程序.我希望我的应用的用户能够与他们的社交图进行交互(即发布到他们的流).为此,我将使用Facebook iOS SDK.
当用户已经通过Facebook进行身份验证时,他们也应该能够在我的应用程序的服务器端使用某些服务.如何根据服务器上的服务验证用户?
在我的iOS应用程序中,我可以使用iOS Facebook SDK查询访问令牌(对于我的Facebook应用程序).我应该将该访问令牌与facebook用户ID一起发送到我的服务器吗?服务器可以验证访问令牌是否有效吗?或者只应该我的iOS应用程序与Facebook API进行通信?服务器可以发布到我的Facebook墙上,还是应该通过iOS应用程序完成?
我想检索登录的用户所在国家/地区,并将其插入到div中.我成功地使用用户姓名,性别和年龄范围,但有些人为什么我无法检索国家.这是我的代码:
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me?fields=name,email,gender,age_range,picture,country', function (response) {
document.getElementById('status').innerHTML = response.name + ",";
document.getElementById('status1').innerHTML = response.gender + ",";
document.getElementById('status2').innerHTML = (response.age_range.min) + "-" + (response.age_range.min + 1) + " years old";
document.getElementById('status3').innerHTML = response.country;
}
Run Code Online (Sandbox Code Playgroud)
谢谢!