美文网首页
微博登陆

微博登陆

作者: Maiiiiiiiiiiiid | 来源:发表于2019-04-28 12:49 被阅读0次

微博登陆

[TOC]


1.第一次请求:首先访问使用第一个授权API

在idnex/Api/index的视图里面用button的点击事件跳转到:

https://api.weibo.com/oauth2/authorize?client_id=154815301&response_type=code&redirect_uri=http://www.tp5.com/tp5_03/public/index/api/weibo

参数client_id redirect_uri

返回给你设定的授权回调页一个CODE 用于表示授权成功的码(动态生成)

之后会跳转你自己设定回调url . “?code=192ccba787e51a72e9b90c50805f6a2e”

2.自己的回调url传参

​ 传入code

3.第二次请求(使用POST):

https://api.weibo.com/oauth2/access_token?client_id=154815301&client_secret=92c786f162cd3935ce7d64bbaaf2c8f4&grant_type=authorization_code&redirect_uri=http://www.tp5.com/tp5_03/public/index/api/weibo&code=7daeeea6fd7481c6aad8431710fccaae

参数:client_id client_secret redirect_uri 以及上一个API返回的CODE

返回:

Array
(
    [access_token] => 2.00rF8DvG0zWaTK71839f71c7AJWKYC
    [remind_in] => 157679999
    [expires_in] => 157679999
    [uid] => 6339867279
    [isRealName] => true
)

access_token 对应的是授权的用户

index/Api/weibo

public function weibo(){
    //获取code
    $code = input('code');
    echo $code;
    //        exit();
    //POST获取开始
    $tom = "https://api.weibo.com/oauth2/access_token?client_id=154815301&client_secret=92c786f162cd3935ce7d64bbaaf2c8f4&grant_type=authorization_code&redirect_uri=http://www.tp5.com/tp5_03/public/index/api/weibo&code=".$code;
    $url = $tom;
    header("Content-type:text/html;charset=utf-8");
    $curl = curl_init();
    curl_setopt($curl,CURLOPT_URL,$url);
    curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($curl,CURLOPT_POST,TRUE);
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($curl,CURLOPT_USERPWD,"username:passward");
    $data = curl_exec($curl);
    curl_close($curl);
    $result = json_decode($data,true);


    echo "<pre>";print_r($result);echo "</pre>";
    
    $access_token =  $result['access_token'];
    $uid =  $result['uid'];

    echo $access_token;
    echo "登陆成功";
}

上面我们就能获取换取Access Token

4.第三次请求用户数据

https://api.weibo.com/2/statuses/public_timeline.json?access_token=abcd

//获取授权用户数据
$access_token =  $result['access_token'];
$uid =  $result['uid'];

//可以get
$tom = "https://api.weibo.com/2/users/show.json?access_token=" . $access_token . "&uid=" . $uid;
$data = file_get_contents($tom,'rb');

$data = json_decode($data,true);

echo "/********************************/";
echo "<pre>";print_r($data);echo "</pre>";

获取的$data用户数据我放到最后

<center>End.</center>


ps:

我是用的是没通过审核的应用

注意调试时不要在第二个请求直接刷新,会得到类似的返回值:

Array
(
 [error] => invalid_grant
 [error_code] => 21325
 [request] => /oauth2/access_token
 [error_uri] => /oauth2/access_token
 [error_description] => invalid authorization code:3ed09c0168eebf93713d2511b4119c1d
)

官方文档:https://open.weibo.com/wiki/Connect/login?tdsourcetag=s_pctim_aiomsg

授权的用户数据<a name="data"></a>:

Array
    (
    [id] => 6339867279
    [idstr] => 6339867279
    [class] => 1
    [screen_name] => Maiiiiiid
    [name] => Maiiiiiid
    [province] => 100
    [city] => 1000
    [location] => 其他
    [description] => 
    [url] => 
    [profile_image_url] => http://tvax2.sinaimg.cn/crop.0.0.996.996.50/006V3r5Rly8fshts00jsyj30ro0rotal.jpg
    [cover_image_phone] => http://ww1.sinaimg.cn/crop.0.0.640.640.640/549d0121tw1egm1kjly3jj20hs0hsq4f.jpg
    [profile_url] => u/6339867279
    [domain] => 
    [weihao] => 
    [gender] => m
    [followers_count] => 20
    [friends_count] => 153
    [pagefriends_count] => 0
    [statuses_count] => 2
    [video_status_count] => 0
    [favourites_count] => 62
    [created_at] => Mon Aug 07 12:18:15 +0800 2017
    [following] => 
    [allow_all_act_msg] => 
    [geo_enabled] => 1
    [verified] => 
    [verified_type] => -1
    [remark] => 
    [insecurity] => Array
    (
        [sexual_content] => 
    )

    [status] => Array
    (
        [created_at] => Sat Apr 27 09:24:35 +0800 2019
        [id] => 4.3656195641262E+15
        [idstr] => 4365619564126181
        [mid] => 4365619564126181
        [can_edit] => 
        [show_additional_indication] => 0
        [text] => 转发微博
        [source_allowclick] => 0
        [source_type] => 1
        [source] => 微博 weibo.com
        [favorited] => 
        [truncated] => 
        [in_reply_to_status_id] => 
        [in_reply_to_user_id] => 
        [in_reply_to_screen_name] => 
        [pic_urls] => Array
        (
        )

        [geo] => 
        [is_paid] => 
        [mblog_vip_type] => 0
        [reposts_count] => 0
        [comments_count] => 0
        [attitudes_count] => 0
        [pending_approval_count] => 0
        [isLongText] => 
        [reward_exhibition_type] => 0
        [hide_flag] => 0
        [mlevel] => 0
        [visible] => Array
        (
            [type] => 0
            [list_id] => 0
        )

        [biz_feature] => 0
        [hasActionTypeCard] => 0
        [darwin_tags] => Array
        (
        )

        [hot_weibo_tags] => Array
        (
        )

        [text_tag_tips] => Array
        (
        )

        [mblogtype] => 0
        [rid] => 0
        [userType] => 0
        [more_info_type] => 0
        [positive_recom_flag] => 0
        [content_auth] => 0
        [gif_ids] => 
        [is_show_bulletin] => 2
        [comment_manage_info] => Array
        (
            [comment_permission_type] => -1
            [approval_comment_type] => 0
        )

    )

    [ptype] => 0
    [allow_all_comment] => 1
    [avatar_large] => http://tvax2.sinaimg.cn/crop.0.0.996.996.180/006V3r5Rly8fshts00jsyj30ro0rotal.jpg
    [avatar_hd] => http://tvax2.sinaimg.cn/crop.0.0.996.996.1024/006V3r5Rly8fshts00jsyj30ro0rotal.jpg
    [verified_reason] => 
    [verified_trade] => 
    [verified_reason_url] => 
    [verified_source] => 
    [verified_source_url] => 
    [follow_me] => 
    [like] => 
    [like_me] => 
    [online_status] => 0
    [bi_followers_count] => 13
    [lang] => zh-cn
    [star] => 0
    [mbtype] => 0
    [mbrank] => 0
    [block_word] => 0
    [block_app] => 0
    [credit_score] => 80
    [user_ability] => 0
    [urank] => 9
    [story_read_state] => -1
    [vclub_member] => 0
    [is_teenager] => 0
    [is_guardian] => 0
    [is_teenager_list] => 0
)

相关文章

  • 微博登陆

    微博登陆 [TOC] 1.第一次请求:首先访问使用第一个授权API 在idnex/Api/index的视图里面用b...

  • 写在女儿五岁生日前

    2019-06-25 昨天看Peachmama的微博,想登陆微博关注,结果忘了密码,一直登陆不了,用手机号登陆,竟...

  • PHP 微博登陆

    利用微博wap版域名进行登陆

  • 新浪微博登陆

    使用python实现新浪微博登陆首先打开charles,记录从打开浏览器到新浪微博登陆成功的全部http请求打开新...

  • 第三方之联合登陆(微信)

    前言 App联合登陆很常用,包括使用qq、微信、微博账号登陆等,这篇记录下微信登陆的接入流程。 接入流程 1:申请...

  • 攻克微博(1) - 模拟微博登陆

    思路 对于爬虫来说,模拟登陆成功=获取可以直接使用的cookie,这样就可以告诉服务器你属于登陆状态然后直接开始访...

  • 2019-07-24第三方登录

    微博登录 微博登陆声明 qq登录 QQ登陆声明 这个是让网站加入QQ登录接口,这段代码可放在 之间。申请腾讯接口...

  • 探讨APP登录设计方式以及如何设计登录模块

    1、熟悉目前常见的手机APP登陆方式 ① 账号登陆(手机、邮箱) ② 第三方登陆(微信,QQ,微博) ③ 一键快捷...

  • 朋友人在国外,谨防诈骗

    今天上午收到大学室友的微博新号好友申请,说是在国外网络受限无法登陆微信等,只能登陆微博国际版,所以申请了新的账号来...

  • 使用node搭建自动发图文微博机器人

    仅供学习交流,请勿用于商业用途,并遵守新浪微博相关规定。 代码目录 此微博机器人的实现功能如下: 模拟登陆新浪微博...

网友评论

      本文标题:微博登陆

      本文链接:https://www.haomeiwen.com/subject/ksjdnqtx.html