React Native component for auth with twitter
- Xcode 8+
- iOS 8.0+
- CocoaPods 1.1.1+
- Minimum SDK 16
Run npm install --save tipsi-twitter to add the package to your app's dependencies.
Run react-native link tipsi-twitter so your project is linked against your Xcode project and all CocoaPods dependencies are installed.
- Setup your
Podfilelike the included example/ios/Podfile then runpod install. - Open your project in Xcode workspace.
- Drag the following folder into your project:
node_modules/tipsi-twitter/ios/TPSTwitterModule/
- Open your project in Xcode, right click on Libraries and click
Add Files to "Your Project Name". - Look under
node_modules/tipsi-twitter/iosand addTPSTwitterModule.xcodeproj. - Add
libTPSTwitterModule.atoBuild Phases->Link Binary With Libraries. - Click on
TPSTwitterModule.xcodeprojin Libraries and go the Build Settings tab. Double click the text to the right ofHeader Search Pathsand verify that it has$(SRCROOT)/../../react-native/Reactas well as${SRCROOT}/../../../ios/Pods/Headers/Public- if they aren't, then add them. This is so Xcode is able to find the headers that theTPSTwitterModulesource files are referring to by pointing to the header files installed within thereact-nativenode_modulesdirectory. - Whenever you want to use it within React code now you can:
import TwitterAuth from 'tipsi-twitter'
Run react-native link tipsi-twitter so your project is linked against your Android project
- In your app build.gradle add:
... dependencies { ... compile project(':tipsi-twitter') compile "com.facebook.react:react-native:+" // From node_modules }- In your settings.gradle add:
... include ':tipsi-twitter' project(':tipsi-twitter').projectDir = new File(rootProject.projectDir, '../node_modules/tipsi-twitter/android')- In your AndroidManifest.xml add:
<application ... <meta-data android:name="io.fabric.ApiKey" android:value="YOUR_FABRIC_API_KEY" /> </application>import React, { Component } from 'react' import { View, Button } from 'react-native' import TwitterAuth from 'tipsi-twitter' TwitterAuth.init({ twitter_key: '<TWITTER_KEY>', twitter_secret: '<TWITTER_SECRET>', }) class TwitterLogin extends Component { handleTwitterLoginFinished = async () => { try { const result = await TwitterAuth.login() console.log('User id:', result.userId) } catch (error) { console.log('Login error:', error) } } render() { return ( <View> <Button title="Twitter Login Button" onPress={this.handleTwitterLoginFinished} /> </View> ) } }A result object will be returned after successful Twitter auth.
An object with the following keys:
authTokenString - Twitter token for auth in your app.authTokenSecretString - Twitter secret for auth in your app.userIDString - Twitter user id.userNameString - Twitter user name.
To run example app e2e tests for all platforms you can use npm run ci command. Before running this command you need to specify TWITTER_KEY, TWITTER_SECRET and TWITTER_EMAIL, TWITTER_USER, TWITTER_PASS environment variables:
TWITTER_KEY=<...> TWITTER_SECRET=<...> TWITTER_EMAIL=<...> TWITTER_USER=<...> TWITTER_PASS=<...> npm run ci- Go to example folder
cd example - Install CocoaPods dependencies (iOS only)
pod install --project-directory=ios - Install npm dependencies
npm install - Configure project before build
TWITTER_KEY=<...> TWITTER_SECRET=<...> npm run configure - Build project:
npm run build:ios- for iOSnpm run build:android- for Androidnpm run build- for both iOS and Android
- Open Appium in other tab
npm run appium - Run tests:
TWITTER_EMAIL=<...> TWITTER_USER=<...> TWITTER_PASS=<...> npm run test:ios- for iOSTWITTER_EMAIL=<...> TWITTER_USER=<...> TWITTER_PASS=<...> npm run test:android- for AndroidTWITTER_EMAIL=<...> TWITTER_USER=<...> TWITTER_PASS=<...> npm run test- for both iOS and Android
You might encounter the following error while trying to run tests:
An unknown server-side error occurred while processing the command. Original error: Command \'/bin/bash Scripts/bootstrap.sh -d\' exited with code 1
This can be fixed by installing Carthage:
brew install carthageTo see more of the tipsi-twitter in action, check out the source at example folder.
tipsi-twitter is available under the MIT license. See the LICENSE file for more info.