react-native-weibo-login

React Native App接入微博登陆,不需要分享,在github找到了react-native-weibo,可惜该库已经一年没有更新,使用的不是最新的微博SDK( android SDK版本:4.1,ios SDK版本3.2.1 ),不能很好的兼容最新的RN( 0.55.4 )版本,所以自己动手写了一个库react-native-weibo-login,该库只实现了微博登陆,没实现分享功能。使用方法如下(也可以在github上查看):

Getting started

$ npm install react-native-weibo-login --save
or
yarn add react-native-weibo-login

Mostly automatic installation

$ react-native link react-native-weibo-login

Manual installation

iOS

  • Add node_modules/react-native-weibo-login/ios/WeiboSDK.bundle in you project, or else it will be crash.
  • In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name], Go to node_modulesreact-native-weibo-login and add RCTWeiBo.xcodeproj.
  • In XCode, in the project navigator, select your project.

    Add

    • libRCTWeiBo.a
    • QuartzCore.framework
    • ImageIO.framework
    • SystemConfiguration.framework
    • Security.framework
    • CoreTelephony.framework
    • CoreText.framework
    • UIKit.framework
    • Foundation.framework
    • CoreGraphics.framework
    • Photos.framework
    • libz.tbd
    • libsqlite3.tbd

    to your project’s Build PhasesLink Binary With Libraries.

    1. In the project navigator, in TargetsinfoURL types. Add new URL type, Identifier value is com.weibo, URL Schemes value is wb + you weibo appKey, such as: wb2317411734.
    2. Right click Info.plist open as source code, insert the following lines:
<key>LSApplicationQueriesSchemes</key>
<array><string>sinaweibohd</string><string>weibosdk</string><string>sinaweibo</string><string>weibosdk2.5</string>
</array>
  1. Copy the following in AppDelegate.m:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{return [RCTLinkingManager application:application openURL:urlsourceApplication:sourceApplication annotation:annotation];
}

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java

    • Add import com.gratong.WeiBoPackage; to the imports at the top of the file.
    • Add new WeiBoPackage() to the list returned by the getPackages() method.
  2. Append the following lines to android/settings.gradle:
include ':react-native-weibo-login'
project(':react-native-weibo-login').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-weibo-login/android')
  1. Insert the following lines inside the dependencies block in android/app/build.gradle:
compile project(':react-native-weibo-login')
  1. Insert the following lines inside the allprojects block in android/build.gradle:
maven { url "https://dl.bintray.com/thelasterstar/maven/" }

such as:

allprojects {repositories {mavenLocal()jcenter()maven { url "https://dl.bintray.com/thelasterstar/maven/" }}
}

Config

  • appKey: 你在微博开放平台上申请的应用ID
  • scope:OAuth2.0 授权机制中 authorize 接口的一个参数。通过 Scope,平台将开放更多的微博核心功能给开发者,同时也加强用户隐私保护,提升了用户体验,用户在新 OAuth2.0 授权页中有权利选择赋予应用的功能。
    目前 Scope 支持传入多个 Scope 权限,用逗号分隔。赋值为all代表请求所有scope权限。
    关于 Scope 概念及注意事项,请查看:http://open.weibo.com/wiki/Scope
  • redirectURI:默认 https://api.weibo.com/oauth2/default.html,必须和sina微博开放平台中应用高级设置中的redirectURI设置的一致,不然会登录失败

Usage

import * as WeiBo from 'react-native-weibo-login';let config = {appKey:"2317411734",scope: 'all',       redirectURI: 'https://api.weibo.com/oauth2/default.html',
}WeiBo.login(config).then(res=>{  console.log('login success:',res)//登陆成功后打印出的数据如下:// { //     refreshToken: '2.00Gc2PbDcecpWC127d0bc690FE7TzD',//     type: 'WBAuthorizeResponse',//     expirationDate: 1686362993740.243,//     userID: '3298780934',//     errCode: 0,//     accessToken: '2.00Gc2PbDcecpWCa981899f410o5hEX' // }}).catch(err=>{ console.log('login fail:',err)})

React Native 微博登陆相关推荐

  1. React Native 轻松集成分享功能(Android 篇)

    关于推送的集成请参考这篇文章,关于统计的集成请参考这篇文章,本篇文章将引导你集成分享功能. 在集成插件之前,需要在各大开放平台上成功注册应用,并通过审核(支持 3 个可选的主流平台).支持的平台如下: ...

  2. [译] Airbnb 在 React Native 上下的赌注(一):概述

    原文地址:React Native at Airbnb 原文作者:Gabriel Peal 译文出自:掘金翻译计划 本文永久链接:https://github.com/xitu/gold-miner/ ...

  3. React Native集成Redux框架讲解与应用

    学过React Native的都知道,RN的UI是根据相应组件的state进行render的,而页面又是由大大小小的组件构成,导致每个组件都必须维护自身的一套状态,因此当页面复杂化的时候,管理stat ...

  4. 【React Native开发】React Native控件之DrawerLayoutAndroid抽屉导航切换组件解说(13)

    转载请标明出处: http://blog.csdn.net/developer_jiangqq/article/details/50599951 本文出自:[江清清的博客] (一)前言 [好消息]个人 ...

  5. React Native开发总结(二)

    58车商通RN落地实践 引言 开发已经经历了几个阶段,从Native App 到 WebApp大火,再到苹果公司禁Web,又发展到了Hybrid的Web与原生共生.再到React Native,这种利 ...

  6. 【React Native开发】React Native控件之RefreshControl组件具体解释(21)

    转载请标明出处: http://blog.csdn.net/developer_jiangqq/article/details/50672747 本文出自:[江清清的博客] (一)前言 [好消息]个人 ...

  7. React Native 每日一学(Learn a little every day)

    本文出自<React Native学习笔记>系列文章. 每天一个知识点(技巧,经验,填坑日记等),每天学一点,离大神近一点. 汇聚知识,分享精华. 如果你是一名React Native爱好 ...

  8. Pano React Native SDK 来了!快速实现移动端音视频和白板

    前言 React Native 是 Facebook 于2015年4月开源的跨平台移动应用开发框架,支持iOS和安卓两大平台.React Native 着力于提高多平台开发的开发效率 -- Learn ...

  9. React Native 移动开发入门与实战

    课程简介 本课程主要讲解 React 的基础知识及应用案例,包括 props.state.生命周期函数等,样式和 Flex 布局,React Native 内置的 API 和 UI 组件介绍.路由.状 ...

  10. React Native专题

    未经授权不得转载: 出处地址:http://www.lcode.org 本文出自:[江清清的技术专栏] 本React Native讲解专题:主要讲解了React Native开发,由基础环境搭建配置入 ...

最新文章

  1. Google CEO Sundar Pichai :“谷歌最大的威胁就是自身的成功”
  2. audio 上一首 下一首 自定义样式_HTML5中 audio标签的样式修改
  3. php图片抖动,css3,jquery_css3图片抖动,css3,jquery - phpStudy
  4. 实验7-3-1 字符串逆序 (15分)
  5. 超级灰色按钮克星1.4.1309.12
  6. Fit项目分页组件的编写
  7. ftp 服务器创建访问连接抱错_如何用固定IP连接FTP服务器?
  8. hadoop安装(超详细)
  9. 基于热传导方程的高温作业专用服装设计(一)
  10. wps文字表格制作拼音田字格模板_手把手教你用wps表格excel制作田字格书法练习字帖...
  11. linux5.8启动mysql命令_linux的定时重启的具体命令? 非常感谢。。。
  12. 优秀!3位95后硕士一作发表Nature!
  13. c语言辗转求最小公倍数,c语言:辗转相除法求最大公约数、最小公倍数
  14. MATLAB及Simulink----基本知识简介
  15. Qt 之QDockwidget 自定义窗口标题栏
  16. 妻子写给丈夫情人的催泪信
  17. uci拒绝认证_关于车架上UCI认证贴纸的10个常见问题
  18. win7系统设置电脑自动开机的操作方法
  19. Android 5.1 长按power键流程分析
  20. c语言注释符号 井号,读c语言深度剖析 -- 符号 注释符号

热门文章

  1. instead of触发器
  2. 大数据与云计算之间的关系
  3. 张小龙的话与微信的玄机
  4. win10查看所有的wifi密码。
  5. Image2LaTeX + AxMath:公式自动识别 + word 编辑公式
  6. python雷达成像(SAR)仿真:(三)徙动校正+方位压缩(完结)
  7. 软路由和OpenWrt/LEDE
  8. coding部署博客 + 腾讯云 cdn 踩坑日记
  9. 3.5.3 连接偏移量管理器
  10. phpStudy安装框架教程