Giter Site home page Giter Site logo

watanabeyu / react-native-simple-twitter Goto Github PK

View Code? Open in Web Editor NEW
87.0 3.0 45.0 2.01 MB

Twitter API client for react native without react-native link and react custom hook

License: MIT License

JavaScript 7.42% TypeScript 92.58%
react-native expo twitter-api javascript twitter typescript customhooks

react-native-simple-twitter's Introduction

If you have request, Please send a PR or issue.

  • please see CHANGELOG.md
  • TWLoginButton / twitter.get() / twitter.post() will be removed on next version (v3.1.0).

React-Native-Simple-Twitter v3.0

Twitter API client for React Native without react-native link.
This package don't use NativeModule, only pure javascript.
So don't need to use react-native link and Expo can also easily use twitter API without auth0 and server.

You can use custom hooks from v3.0

...
import { useTwitter } from "react-native-simple-twitter";

function Login() {
  // if login, please set onSuccess
  const { twitter,TWModal } = useTwitter({
    onSuccess:(user,accessToken) => {
      console.log(user);
      console.log(accessToken);
    }
  });

  const onLoginPress = async () => {
    try {
      await twitter.login();
    } catch(e) {
      console.log(e.errors);
    }
  }

  useEffect(() => {
    twitter.setConsumerKey("key","secret");
  },[]);

  ...

  return (
    <View>
      <Text onPress={onLoginPress}>login</Text>
      <TWModal />
    </View>
  )
}

Checkout v3.x example.

Previous version -> v2.4.1

Installation

This package use WebView, but WebView from react-native is deprecated, so you download with react-native-webview.

$ npm install react-native-simple-twitter react-native-webview --save

if you want to use more twitter types, use abraham/twitter-d

$ npm install --save-dev twitter-d

Demo

demo gif

useTwitter API

import { useTwitter } from 'react-native-simple-twitter';

const { twitter, TWModal } = useTwitter({
  onSuccess:(user,accessToken) => void,
  onError?:(err) => void,
})

useTwitter()

Name Description
onSuccess:(user,accessToken) => void return loggedin user object and access token
onError?:(err) => void if login failed, call this method

twitter

Name Description
twitter.login() Get login url and open TWModal
twitter.setConsumerKey(consumer_key,consumer_key_secret) set application key and secret
twitter.getAccessToken() get access_token and access_token_secret, when user logged in app
twitter.setAccessToken(access_token,access_token_secret) set user access_token and access_token_secret, when you already have access_token and access_token_secret
`twitter.api("GET" "POST"
twitter.get(endpoint,parameters) alias of twitter.api. this method will be deprecated
twitter.post(endpoint,parameters) alias of twitter.api. this method will be deprecated

Other API

  • decodeHTMLEntities
import { decodeHTMLEntities } from 'react-native-simple-twitter'

console.log(decodeHTMLEntities("&amp; &apos; &#x27; &#x2F; &#39; &#47; &lt; &gt; &nbsp; &quot;"))

Tweet is include htmlencoded characters.
So this function decode special characters.

  • getRelativeTime
import { getRelativeTime } from 'react-native-simple-twitter'

console.log(getRelativeTime(new Date(new Date().getTime() - 32390)))
console.log(getRelativeTime("Thu Apr 06 15:28:43 +0000 2017"))

Tweet created_at convert to relative time. ex) 1s 15m 23h

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.