{"id":20160588,"url":"https://github.com/reactnativecn/react-native-weibo","last_synced_at":"2025-04-13T06:36:22.983Z","repository":{"id":57341344,"uuid":"49044521","full_name":"reactnativecn/react-native-weibo","owner":"reactnativecn","description":null,"archived":false,"fork":false,"pushed_at":"2017-08-31T05:30:43.000Z","size":12879,"stargazers_count":124,"open_issues_count":38,"forks_count":85,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-24T08:21:12.574Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reactnativecn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-05T05:37:22.000Z","updated_at":"2024-04-10T14:20:47.000Z","dependencies_parsed_at":"2022-09-08T01:51:25.352Z","dependency_job_id":null,"html_url":"https://github.com/reactnativecn/react-native-weibo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactnativecn%2Freact-native-weibo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactnativecn%2Freact-native-weibo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactnativecn%2Freact-native-weibo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactnativecn%2Freact-native-weibo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reactnativecn","download_url":"https://codeload.github.com/reactnativecn/react-native-weibo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675300,"owners_count":21143763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T00:14:49.803Z","updated_at":"2025-04-13T06:36:22.941Z","avatar_url":"https://github.com/reactnativecn.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-weibo\n\nReact Native的新浪微博登录插件, react-native版本需要0.17.0及以上\n## 如何安装\n\n### 1.首先安装npm包\n\n```bash\nnpm install react-native-weibo --save\n```\n\n### 2.link\n#### 自动link方法\n\n```bash\nreact-native link\n```\n\n#### 手动link~（如果不能够自动link）\n#####ios\na.打开XCode's工程中, 右键点击Libraries文件夹 ➜ Add Files to \u003c...\u003e\nb.去node_modules ➜ react-native-weibo ➜ ios ➜ 选择 RCTWeiboAPI.xcodeproj\nc.在工程Build Phases ➜ Link Binary With Libraries中添加libRCTWeiboAPI.a\n\n#####Android\n\n```\n// file: android/settings.gradle\n...\n\ninclude ':react-native-weibo'\nproject(':react-native-weibo').projectDir = new File(settingsDir, '../node_modules/react-native-weibo/android')\n```\n\n```\n// file: android/app/build.gradle\n...\n\ndependencies {\n    ...\n    compile project(':react-native-weibo')\n}\n```\n\n`android/app/src/main/java/\u003c你的包名\u003e/MainApplication.java`中添加如下两行：\n\n```java\n...\nimport cn.reactnative.modules.weibo.WeiboPackage;  // 在public class MainApplication之前import\n\npublic class MainApplication extends Application implements ReactApplication {\n\n  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {\n    @Override\n    protected boolean getUseDeveloperSupport() {\n      return BuildConfig.DEBUG;\n    }\n\n    @Override\n    protected List\u003cReactPackage\u003e getPackages() {\n      return Arrays.\u003cReactPackage\u003easList(\n          new WeiboPackage(), // 然后添加这一行\n          new MainReactPackage()\n      );\n    }\n  };\n\n  @Override\n  public ReactNativeHost getReactNativeHost() {\n      return mReactNativeHost;\n  }\n}\n```\n\n### 3.工程配置\n#### ios配置\n将`node_modules/react-native-weibo/ios/libWeiboSDK/WeiboSDK.bundle`加入到工程中(必须，很重要，不然登录的时候会crash)\n\n在工程target的`Build Phases-\u003eLink Binary with Libraries`中加入`libRCTWeiboAPI.a、libsqlite3.tbd、libz.tbd、ImageIO.framework、SystemConfiguration.framework、Security.framework、CoreTelephony.framework、CoreText.framework`\n\n\n在`Info-\u003eURL Types` 中增加QQ的scheme： `Identifier` 设置为`sina`, `URL Schemes` 设置为你注册的微博开发者账号中的APPID，需要加前缀`wb`，例如`wb1915346979`\n\n在你工程的`AppDelegate.m`文件中添加如下代码：\n\n```\n#import \"../Libraries/LinkingIOS/RCTLinkingManager.h\"\n\n\n- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {\n  return [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation];\n}\n\n```\n\n##### iOS9的适配问题\n\n由于iOS9的发布影响了微博SDK与应用的集成方式，为了确保好的应用体验，我们需要采取如下措施：\n##### a.对传输安全的支持\n在iOS9系统中，默认需要为每次网络传输建立SSL。解决这个问题：\n\n- 将NSAllowsArbitraryLoads属性设置为YES，并添加到你应用的plist中\n- \n\t\u003ckey\u003eNSAppTransportSecurity\u003c/key\u003e\n\t\u003cdict\u003e\n\t\u003ckey\u003eNSAllowsArbitraryLoads\u003c/key\u003e\n\t\u003c/true\u003e\n\t\u003c/dict\u003e\n\n###### b.对应用跳转的支持\n如果你需要用到微博的相关功能，如登陆，分享等。并且需要实现跳转到微博的功能，在iOS9系统中就需要在你的app的plist中添加下列键值对。否则在canOpenURL函数执行时，就会返回NO。了解详情请至[https://developer.apple.com/videos/wwdc/2015/?id=703](https://developer.apple.com/videos/wwdc/2015/?id=703)\n\n-\n\t\u003ckey\u003eLSApplicationQueriesSchemes\u003c/key\u003e\n\t\u003carray\u003e\n\t\t\u003cstring\u003esinaweibohd\u003c/string\u003e\n\t\t\u003cstring\u003esinaweibo\u003c/string\u003e\n\t\t\u003cstring\u003eweibosdk\u003c/string\u003e\n\t\t\u003cstring\u003eweibosdk2.5\u003c/string\u003e\n\t\u003c/array\u003e\n\t\n\n#### Android\n\n在`android/app/build.gradle`里，defaultConfig栏目下添加如下代码：\n\n```\nmanifestPlaceholders = [\n    WB_APPID: \"微博的APPID\"\t\t//在此修改微博APPID\n]\n```\n\n如果react-native版本\u003c0.18.0,确保你的MainActivity.java中有`onActivityResult`的实现：\n\n```java\nprivate ReactInstanceManager mReactInstanceManager;\n@Override\npublic void onActivityResult(int requestCode, int resultCode, Intent data){\n    super.onActivityResult(requestCode, resultCode, data);\n    mReactInstanceManager.onActivityResult(requestCode, resultCode, data);\n}\n```\n\n## 如何使用\n\n### 引入包\n\n```\nimport * as WeiboAPI from 'react-native-weibo';\n```\n\n### API\n\n#### WeiboAPI.login(config)\n\n```javascript\n// 登录参数 \nconfig : {\t\n\tscope: 权限设置, // 默认 'all'\n\tredirectURI: 重定向地址, // 默认 'https://api.weibo.com/oauth2/default.html'(必须和sina微博开放平台中应用高级设置中的redirectURI设置的一致，不然会登录失败)\n}\n```\n\n返回一个`Promise`对象。成功时的回调为一个类似这样的对象：\n\n```javascript\n{\n\t\"accessToken\": \"2.005e3HMBzh7eFCca6a3854060GQFJf\",\n\t\"userID\": \"1098604232\"\n\t\"expirationDate\": \"1452884401084.538\"\t\n\t\"refreshToken\": \"2.005e3HMBzh8eFC3db19a18bb00pvbp\"\n}\n```\n\n#### WeiboAPI.share(data)\n\n分享到微博\n\n```javascript\n// 分享文字\n{\t\n\ttype: 'text', \n\ttext: 文字内容,\n}\n```\n\n```javascript\n// 分享图片\n{\t\n\ttype: 'image',\n\ttext: 文字内容,\t\n\timageUrl: 图片地址\t\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactnativecn%2Freact-native-weibo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freactnativecn%2Freact-native-weibo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactnativecn%2Freact-native-weibo/lists"}