新浪微博登录模块
npm install react-native-weibo-login-kun$ npm install react-native-weibo-login-kun --save
or
yarn add react-native-weibo-login-kun
$ react-native link react-native-weibo-login-kun
#### iOS
1. Add node_modules/react-native-weibo-login-kun/ios/WeiboSDK.bundle in you project, or else it will be crash.
!add_weibosdk_bundle
2. In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name], Go to node_modules ➜ react-native-weibo-login-kun and add RCTWeiBo.xcodeproj.
3. 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 Phases ➜ Link Binary With Libraries.
4. In the project navigator, in Targets ➜ info ➜ URL types. Add new URL type, Identifier value is com.weibo, URL Schemes value is wb + you weibo appKey, such as: wb2317411734.
5. Right click Info.plist open as source code, insert the following lines:
``xml`
AppDelegate.m
6. Copy the following in :``
- (BOOL)application:(UIApplication )application openURL:(NSURL )url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [RCTLinkingManager application:application openURL:url
sourceApplication:sourceApplication annotation:annotation];
}
#### Android
1. Open up android/app/src/main/java/[...]/MainActivity.javaimport com.gratong.WeiBoPackage;
- Add to the imports at the top of the file.new WeiBoPackage()
- Add to the list returned by the getPackages() method.android/settings.gradle
2. Append the following lines to :`
`
include ':react-native-weibo-login-kun'
project(':react-native-weibo-login-kun').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-weibo-login-kun/android')
android/app/build.gradle
3. Insert the following lines inside the dependencies block in :`
`
compile project(':react-native-weibo-login-kun')
android/build.gradle
4. Insert the following lines inside the allprojects block in :`
`
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
`
such as:
`
allprojects {
repositories {
mavenLocal()
jcenter()
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
}
}
代表请求所有scope权限。关于 Scope 概念及注意事项,请查看:http://open.weibo.com/wiki/Scope
- redirectURI:默认 https://api.weibo.com/oauth2/default.html,必须和sina微博开放平台中应用高级设置中的redirectURI设置的一致,不然会登录失败Usage
`javascript
import * as WeiBo from 'react-native-weibo-login-kun';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)
})
``