Introducing npm Teams! Private packages + team management tools.Learn more »

react-native-instagram-login

2.0.0 • Public • Published

React Native Instagram login

npm version npm downloads

IMPORTANT NOTES:

react-native-instagram-login version 2 switches to the Instagram Graph API.

If you want to use old version 1, please read docs

Install

npm install react-native-instagram-login react-native-webview --save

After that run:

react-native link react-native-webview

for ios:

cd ios
pod install
  • How to get appId, appSecret of instagram?

Simple setup, you only need to complete step 3.

Then go to Instagram> Basic Display> Instagram App ID field

This is going to give you an access_token, which one can be used on the new Graph Api, go to https://developers.facebook.com/docs/instagram-basic-display-api/guides/getting-profiles-and-media for docs.

Usage:

 
import InstagramLogin from 'react-native-instagram-login'
import store from 'react-native-simple-store'
<View>
    <TouchableOpacity onPress={()=> this.instagramLogin.show()}>
        <Text style={{color: 'white'}}>Login</Text>
    </TouchableOpacity>
    <InstagramLogin
        ref={ref => (this.instagramLogin = ref)}
        appId='your-app-id'
        appSecret='your-app-secret'
        redirectUrl='your-redirect-Url'
        scopes={['user_profile', 'user_media']}
        onLoginSuccess={ this.setIgToken }
        onLoginFailure={(data) => console.log(data)}
    />
</View>
 
setIgToken = async (data) => {
    await store.save('igToken', data.access_token)
    await store.save('igUserId', data.user_id)
    this.setState({ igToken: data.access_token, igUserId: data.user_id})
}

Props

Property Type Description
appId PropTypes.string Instagram App_id
appSecret PropTypes.string Instagram App_secret
responseType PropTypes.string 'code' or 'token', default 'token'
scopes PropTypes.array Login Permissions
redirectUrl PropTypes.string Your redirectUrl
onLoginSuccess PropTypes.func Function will be call back on success
onLoginFailure PropTypes.func Function will be call back on error
onClose PropTypes.func Function will be call back on close modal
modalVisible PropTypes.bool true or false
renderClose PropTypes.func Render function for customize close button
containerStyle PropTypes.object Customize container style
wrapperStyle PropTypes.object Customize wrapper style
closeStyle PropTypes.object Customize close style

Logout

Currently the react-native-cookies library is not working, so we cannot delete cookies, so temporary the solution is to disable cookies on webview. See more

~To logout use clear cookies by using https://github.com/joeferraro/react-native-cookies~

import CookieManager from 'react-native-cookies';
 
  logout() {
    CookieManager.clearAll()
      .then((res) => {
        console.log('CookieManager.clearAll =>', res);
        this.setState({ token: '' })
      });
  }

## Contributing Special thanks @AlbertoIHP for v2.

This project exists thanks to all the people who contribute. [Contribute].

## Pull request Pull requests are welcome!

Install

npm i react-native-instagram-login

DownloadsWeekly Downloads

1,908

Version

2.0.0

License

ISC

Unpacked Size

1.36 MB

Total Files

69

Last publish

Collaborators

  • avatar