Facebook SDK
<?php
session_start();
header('Content-type:text/html; charset=UTF-8'); require_once './facebook-php-sdk-v4-4.0-dev/autoload.php'; use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper; FacebookSession::setDefaultApplication('3455677266264', 'nnvu8883332fvg550d40f8fcf8e6df2e2'); // 回调获取session
$helper = new FacebookRedirectLoginHelper('http://www.adtuu-server.com/facebook/callback.php'); try {
$session = $helper->getSessionFromRedirect(); } catch(FacebookRequestException $ex) {
// When Facebook returns an error
echo '1:';
var_dump($ex->getMessage());
} catch(\Exception $ex) {
// When validation fails or other local issues
echo '2:';
var_dump($ex->getMessage());
} if ($session) {
// Logged in 这个token返回的 有效期节点没有值
echo $access_token = $session->getToken();
var_dump($session); /* ここで有効期限を延長させてます 60天token有效期*/
$longSession = $session->getLongLivedSession();
$accessToken = $longSession->getToken(); echo '<br />' . $accessToken;
var_dump($longSession); }
exit; //https://developers.facebook.com/docs/graph-api/reference/v2.1/user //$access_token = 'as3s4de4vM3wqSmiSi7jP8ZBg1CPLvKxeJKUWszWV0cfZAoaHMk8CfqA6mjGXC5G1ZBfWCC7IQimExlujpWs1CwayjiAuqtPrZBQBevuyZB9ySEfZAUjMTC6SJsQD1pTp9MEaf8';
$access_token = '2cjiktwxzjzpzP0gINsla10L4ZClsP5KhbCmsO0gf6VUSNPJYJHy7cOiYhwxqYZA0fDALEINcZBZBqGlKHZBXSdygYNUHCQskZC6DfkPmH0ivS6bqdTbdGwViFkiDHZCMw3evAWQ3BNINvMAgVaaWL1xvi2wqEVu70p90hIkt3xVgbbHnAnrfgPA7iCV7z5TXZCx5SKboWvd80JHdq'; $session = new FacebookSession($access_token);
try { $user_profile = (new FacebookRequest(
$session, 'GET', '/me'
))->execute()->getGraphObject(GraphUser::className()); echo "Name: " . $user_profile->getName(); } catch(FacebookRequestException $e) { echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage(); } try {
$friends = (new FacebookRequest(
$session, 'GET', '/me/friendlists'
))->execute()->getGraphObject(GraphUser::className());
var_dump($friends);
} catch (Exception $e) { var_dump($e);
} exit; try { $response = (new FacebookRequest(
$session, 'POST', '/me/feed', array(
'link' => 'http://www.adtuu.com',
'message' => 'Hi, Adtuu !!!'
)
))->execute()->getGraphObject(); echo "Posted with id: " . $response->getProperty('id'); } catch(FacebookRequestException $e) { echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage(); } try { // Upload to a user's profile. The photo will be in the
// first album in the profile. You can also upload to
// a specific album by using /ALBUM_ID as the path
$response = (new FacebookRequest(
$session, 'POST', '/me/photos', array(
'source' => new CURLFile('/Users/zhoutingze/webroot/facebook/post.jpg', 'image/jpeg'),
'message' => 'User provided message'
)
))->execute()->getGraphObject(); // If you're not using PHP 5.5 or later, change the file reference to:
// 'source' => '@/path/to/file.name' echo "Posted with id: " . $response->getProperty('id'); } catch(FacebookRequestException $e) { echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage(); } try { $response = (new FacebookRequest(
$session, 'POST', '/me/feed', array(
'link' => 'http://www.baidu.com/img/bd_logo1.png',
'message' => 'Hi, Adtuu !!!'
)
))->execute()->getGraphObject(); echo "Posted with id: " . $response->getProperty('id'); } catch(FacebookRequestException $e) { echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage(); }
Facebook SDK的更多相关文章
- SDK接入(1)之Android Facebook SDK接入
SDK接入(1)之Android Facebook SDK接入 由于游戏已上线,且处于维护阶段,所以有空写写各种SDK接入过程和遇到的问题,也当作一种工作总结.SDK接入主流分为这么几类,登录.支付. ...
- 在Android上实现使用Facebook登录(基于Facebook SDK 3.5)
准备工作: 1. Facebook帐号,国内开发者需要一个vpn帐号(网页可以浏览,手机可以访问) 2. 使用Facebook的SDK做应用需要一个Key Hashes值. 2 ...
- 计算facebook sdk需要的key hashes
1. 下载openssl,在C盘创建openssl文件夹,解压下载的zip到openssl文件夹. 2. 找到debug.keystore. windows下在C:\Users\用户名\.androi ...
- iOS Facebook SDK
iOS 使用 Facebook SDK 可以登录,分享,发布通知(Notifications)等. 首先下载 Facebook SDK.然后在 Facebook Developer 上注册自己的 ap ...
- FaceBook SDK登录功能实现(Eclipse)
由于公司游戏要进行海外推广,所以要我们接入FBSDK 实现登录,分享,投放,所以写这篇文章,也算是个工作总结.1.资料 (1).FB SDK github源码地址为 (2): [FB SDK中文接入文 ...
- 集成Facebook SDK之Facebook登录
前言 这几天应公司需求,需要在项目中接入facebook的登录,现在闲下来后再次巩固一下! 准备工作 保证自己的网络已经翻墙,能够进入Facebook网页 准备一个FB的开发者账号,如果没有可以免费申 ...
- 集成Facebook SDK
1. 下载SDK https://developers.facebook.com/docs/ios?locale=zh_CN 2. 如何集成 https://developers.facebook.c ...
- 浅谈 facebook .net sdk 应用
今天看了一篇非常好的文章,就放在这里与大家分享一下,顺便也给自己留一份.这段时间一直在学习MVC,另外如果大家有什么好的建议或者学习的地方,也请告知一下,谢谢. 这篇主要介绍如何应用facebook ...
- 应用facebook .net sdk
1.本博客主要介绍如何应用facebook .net SDK,实现发帖.点赞.上传照片视频等功能,更多关于facebook API,请参考:https://developers.facebook.co ...
随机推荐
- Programming Assignment 1: Percolation
问题描述可以详见:http://coursera.cs.princeton.edu/algs4/assignments/percolation.html 关于QuickFindUF的javadoc:h ...
- C#_判断2个对象的值是否相等
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- redis终于有比较大的进展了,redis3.0.1 稳定版本发布,支持集群。
原文地址:https://raw.githubusercontent.com/antirez/redis/3.0/00-RELEASENOTES Redis 3.0 release notes --[ ...
- 模式匹配运算符–Shell
转载:http://www.firefoxbug.net/?p=722 Var=/home/firefox/MyProgram/fire.login.name ${Variable#patte ...
- BestCoder Sequence
hdu 4908 Bestcoder Problem Description Mr Potato is a coder.Mr Potato is the BestCoder. One night, ...
- TCP/IP协议原理与应用笔记17:IP编址(重点)
1. IP地址(通用标识符) 对于同一个网络设备(主机或路由器)的不同网络连接,需要不同的IP地址进行标识 2. 主机标识符 主要有下面三种方式的主机标识方式: (1)Name:是什么,可读性强(了解 ...
- JS 控制文本框只能输入中文、英文、数字与指定特殊符号
想做姓名输入的js判断是否是中文,但是网上找的很多是源于一篇文章的,判断中文的正则式不对,后来找到一个可以准确判断了,但是是监测里面有中文的就行,跟我想要的只能输入中文的意思相左,所以又找了下面的 J ...
- UVA442 Matrix Chain Multiplication 矩阵运算量计算(栈的简单应用)
栈的练习,如此水题竟然做了两个小时... 题意:给出矩阵大小和矩阵的运算顺序,判断能否相乘并求运算量. 我的算法很简单:比如(((((DE)F)G)H)I),遇到 (就cnt累计加一,字母入栈,遇到) ...
- LeetCode 242
Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. For ...
- Reids配置文件redis.conf中文详解
redis的各种配置都是在redis.conf文件中进行配置的. 有关其每项配置的中文详细解释如下: 附redis.conf英文原版: # Redis configuration file examp ...