新浪开放平台注意事项
来源:互联网 发布:数据采集卡ni 编辑:程序博客网 时间:2024/05/21 07:40
1、首先创建web应用,应用创建成功之后会有一个 App Key和App Secret,在调用新浪api和第三方登录会用到
2、想调用微博api首先需要在(微博登录/授权登录)中获得Token 和 Access Token
3、在获取Access Token的时候需要用post提交,但是传值的方式是get方式,如下:
$url='https://api.weibo.com/oauth2/access_token?client_id=2551323065&client_secret=782a0f351a536f44a7c854f74198eb51&grant_type=authorization_code&code='.$code.'&redirect_uri=https://15600781185.applinzi.com/callback.php';
可以用curl模拟post提交:
$ch = curl_init(); //1.初始化 curl_setopt($ch, CURLOPT_URL, $url); //2.请求地址 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST');//3.请求方式 //4.参数如下 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//https curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');//模拟浏览器 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER,array('Accept-Encoding: gzip, deflate'));//gzip解压内容 curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $tmpInfo = curl_exec($ch);//6.执行
4、发布一条微博消息的时候也是post提交,传值方式是get方式,但是在post提交时需要放一个空的json数据
<?php//登录成功返回值$code = $_GET['code'];$curl = new curl();$url = 'https://api.weibo.com/oauth2/access_token?client_id=3266704496&client_secret=9ad731aecbe32f3c0f07cf7df2381b35&grant_type=authorization_code&code='.$code.'&redirect_uri=15600781185.applinzi.com/week1.php';$tmpInfo = $curl->send($url,'POST');$token = json_decode($tmpInfo,true);$access_token = $token['access_token'];//发布微博$content = '我是小狗';$url = 'https://api.weibo.com/2/statuses/update.json?access_token='.$access_token.'&status='.$content;//发送一个空json数据$data = array();$data =json_encode($data);$result = $curl->send($url,'POST',$data);print_r($result);//curl类class curl{function send($url,$method,$data=''){$ch = curl_init(); //1.初始化 curl_setopt($ch, CURLOPT_URL, $url); //2.请求地址 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);//3.请求方式 //4.参数如下 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//https curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');//模拟浏览器 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); if($method=="POST"){//5.post方式的时候添加数据 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $tmpInfo = curl_exec($ch);//6.执行 return $tmpInfo;}}?>
0 0
- 新浪开放平台注意事项
- 新浪微薄开放平台浅析
- 【二维码】新浪开放平台和腾讯开放平台试水
- 新浪围脖开放平台一"各种锁"
- 新浪围脖开放平台三"urlEncode"
- 新浪围脖开放平台四"xml解析"
- 新浪围脖开放平台六"字符串转化"
- 调用新浪微博开放平台接口
- 新浪微博将推游戏开放平台
- 新浪开放平台开发1--认证
- 新浪微博开放平台接入
- 新浪微博开放平台开发总结
- 分享按钮-新浪微博开放平台
- 开放平台:新浪微博 for iOS
- 淘宝、百度、腾讯、新浪开放平台
- 新浪与腾讯的开放平台对比
- 获取新浪开放平台的Access token
- 新浪开放平台接入Python版
- 如何右键新建HTML
- STK Engine简介
- PullToRefresh上下拉刷新使用步骤
- 【读书笔记】《数字图像处理》(第三版)-第2章 数字图像基础
- 单例设计模式深入浅出分析
- 新浪开放平台注意事项
- 分布式计算学习笔记之二:Socket通讯与HTTP服务器
- 面对对象基础概念
- python学习之函数
- android 利用ViewStub标签动态加载布局,节省资源
- opencv函数——cvCreateCapture()
- AJax使用MVC
- 链表结构回顾
- Day3.Java基础之构造方法,继承,多态...