react-native-twitter v0.2.1
react-native-twitter
A Twitter API client library for React Native
Installation
npm i react-native-twitter -S
react-native linkIf you use 3-legged authorization, you need to add the deep link scheme for your callback URL. See React Native docs and example for more info.
Usage
import twitter, {auth} from 'react-native-twitter';auth(tokens, callbackUrl[, options])
Get the client's authentication tokens via 3-legged authorization.
- tokens
consumerKeyYour consumer keyconsumerSecretYour consumer secret
callbackUrlThe URL a user is redirected to, you need to add the deep link scheme for this URLoptionsaccessTypeSpecifyx_auth_access_type, supported values are'read'or'write'(See Twitter docs.)forSignInIftrue, oauth/authenticate endpoint is used instead of oauth/authorize (Default:false)forceLoginSpecifyforce_login(See Twitter docs.) (Default:false)screenNameSpecifyscreen_name(See Twitter docs.)
Returns:
Promiseof{accessToken, accessTokenSecret, id, name}accessTokenAccess tokenaccessTokenSecretAccess token secretidUser idnameScreen name
auth(tokens, pinPromise[, options])
Get the client's authentication tokens via PIN-based authorization.
pinPromisePromisewhich resolves to PINReturns:
Promiseof{accessToken, accessTokenSecret, id, name}
const client = twitter(tokens)
Create a Twitter API client.
- tokens
consumerKeyYour consumer keyconsumerSecretYour consumer secretaccessTokenAccess tokenaccessTokenSecretAccess token secret
const {rest, stream} = twitter(tokens);rest.get(path[, params])
Make GET requests.
pathThe endpoint pathparamsParameters for the requestReturns:
Promise
rest.post(path[, params])
Make POST requests.
pathThe endpoint pathparamsParameters for the requestReturns:
Promise
There is no File or Blob in React Native, but you can use Object with uri property as media files for media uploading endpoints such as account/update_profile_image. Below is an example of changing profile image to the latest photo from CameraRoll.
CameraRoll.getPhotos({first: 1})
.then(({edges: [{node: {image}}]}) => rest.post('account/update_profile_image', {image}))
.then(() => {console.log('done');})
.catch(console.error);stream(path, params) (Android only)
Connect to Streaming APIs.
pathThe endpoint pathparamsParameters for the requestReturns:
EventEmitter'data''error'close()Close the connection