Giter VIP home page Giter VIP logo

react-native-twitter's People

Contributors

piroro-hs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-native-twitter's Issues

Documentation on using auth

An example of using auth will be very helpful. On clicking the sign-in button, I have the following code triggered:

auth({
  consumerKey: CONSUMER_KEY,
  consumerSecret: CONSUMER_SECRET
}, 'retweeter://main')
.then(credentials => {
});

My deep linking is working fine with my AndroidManifest:

<intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data 
            android:scheme="retweeter"
            android:host="main"
        />
</intent-filter>

Error when using rest.get

I am getting one problem when I implement rest.get
var tokens = {
consumerKey: this.state.config.twitter.consumerKey,
consumerSecret: this.state.config.twitter.consumerSecret,
accessToken: this.state.config.twitter.oauth_token,
accessTokenSecret: this.state.config.twitter.oauth_verifier
};
const {rest, stream} = twitter(tokens);
rest.get("account/settings").then(() => {Alert.alert('done');}).catch(console.error);

I get this error :
Error: 89 Invalid or expired token.

Twitter Callback URL not approved

Possible Unhandled Promise Rejection (id: 0):
Error: Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings

Hello,
Thanks for this library. It was working perfectly fine up until a few weeks ago. Now every time I click on login to twitter, instead of linking an external webpage i get this error. I've tried to check the callback URL, whitelisted all the endpoints and still the same. For some reason I'm unable to point to sign in with twitter

Any help or suggestions?

Regards

error when using in mobile azure

typeError: _reactNative.Linking.addEventListener is not a function

  at Object.<anonymous> (node_modules/react-native-twitter/src/oauth/auth.js:49:22)
  at Object.<anonymous> (node_modules/react-native-twitter/src/index.js:7:19)
  at Object.<anonymous> (app.js:23:25)

Response for preflight has invalid HTTP status code 400

Hi guys !

I am getting one problem when I implement rest.post:
rest.post('favorites/create', {} , params) .then( (response) => { console.log(response); })

I get this error :

Failed to load https://api.twitter.com/1.1/favorites/create.json?id=925595570147811328: Response for preflight has invalid HTTP status code 400

Header : Authorization : OAuth oauth_consumer_key="my_customer_key", oauth_nonce="29655190774014173", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1511577580", oauth_token="user_token", oauth_version="1.0", oauth_signature="fB2ZMDv19bsVX55BrpD1pBEyjKk%3D"

I am sure that my Authorization header is working, because It works on Postman.

Clarification on auth(tokens, callbackUrl[, options])

Hello,

I appreciate the time you put into this module. It looks like it will be a big help on my project, but I'm confused about the use of the above method.

according to your "readme" file it returns this "

 Returns: Promise of {accessToken, accessTokenSecret, id, name}

 accessToken Access token
 accessTokenSecret Access token secret
 id User id
 name Screen name

When I call "auth" in my app, it properly redirects to the twitter login page. When I authorize the app, it redirects back to the app, but the ".then" function never gets called.

My code is something like this:

let twitterAccessToken;

auth({tokens, redirectUrl}).then((accessToken)=> twitterAccessToken = accessToken);

unable to send direct message

Hello, I am unable to send a direct message. I have the direct message permission enabled in the developer console & the recipient has direct messages enabled from any user. The error I receive is not much help so any insight would be appreciated. Thank you!
I am using:
"react": "16.4.1",
"react-native": "0.56.0",
"react-native-twitter": "^0.2.1",

error:
err Error at request.js:60 at tryCatch (es6-promise.js:409) at invokeCallback (es6-promise.js:424) at es6-promise.js:176 at MessagePort.flush (es6-promise.js:128)

code:

  const data = {
       "event": {
      "type": "message_create",
      "message_create": {
        "target": {
          "recipient_id": TWITTER_USER_ID_STR
        },
        "message_data": {
          "text": "Hi",
        }
      }
    }
  };

const parsedTokens = (JSON.parse(tokens));
        const { rest } = twitter(parsedTokens);
        rest.post('direct_messages/events/new', data ).then((resp) => {
          console.log('resp', resp);
          dispatch(updateProfileLoading(false));
        }).catch((err) => {
          console.log('err', err);
          dispatch(updateProfileLoading(false));
        });```

POST request giving Error 220 Your credentials do not allow access to this resource

Dear,

I want to send direct msg to followers. I have enabled permission in twitter apps management end. Here is my code

const {rest, stream} = twitter(tokens);

        rest.post('direct_messages/new', [{
            screen_name:'username',
            user_id:'2761567848',
            text:'this is test message'
        }]).then(function(data){
            console.log(data);
        });

Error: 220 Your credentials do not allow access to this resource.

can idea pls? Can u give me any working example of post?

Use Stream API in background

Hello,

I am new to react-native and developing an Android application that notifies the user, if someone from a list of users tweet.

I was able to use the Streaming and REST API's provided by react-native-twitter, and also show notifications using react-native-push-notification separately.

Is it possible to use the stream (using event-emitter) in background state of the app and notify the users when tweets arrive? Could someone share a sample for the same.

auth(tokens, callbackUrl[, options]) clarification and opening twitter for login

Can someone include an example of how to call auth with and without options.

***FIXED: The issue below was due to misspelling the consumerKey and consumerSecret fields.

I also have a problem where when I call auth, twitter doesn't open in safari and I just get a console log of:

Error: 32 Could not authenticate you.
at request.js:58
at tryCallOne (core.js:37)
at core.js:123
at JSTimers.js:118
at Object.callTimer (JSTimersExecution.js:96)
at Object.callImmediatesPass (JSTimersExecution.js:203)
at Object.callImmediates (JSTimersExecution.js:219)
at MessageQueue.__callImmediates (MessageQueue.js:238)
at MessageQueue.js:126
at MessageQueue.__guard (MessageQueue.js:228)

iOS Example

Is this project specific to Android? If not, can you please update the example project to include an iOS example?

I've integrated the library but having real trouble getting the access tokens when the Promise resolves.

Thanks!

auth(tokens, callbackUrl[, options]) not redirecting back to application

After the application has opened the browser to authenticate the user, it does not redirect back to the application.

I've unlocked the "lock callback url" settings in the twitter developer apps settings, and supplied these parameters to my manifest:

<application
      android:name=".MainApplication"
      android:allowBackup="true"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:scheme="appName"
                android:host="main"
            />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

Then the method i used to sign in would be:

signInTwitter(){
      var tokens= {
        consumerKey:         'xxx',
        consumerSecret:      'xxx,         
      };

      callbackUrl = 'appName://main'
      
      auth(tokens, callbackUrl)
      .then((credentials) => {
        console.log(credentials)
      }).catch(console.error);
    }

Not redirected back to the app

I already sign in and redirected to callback url but can't get redirected back to the app. Any solution?

My code looks like this

    const tokens = {
      consumerKey: TWITTER_CONSUMER_KEY,
      consumerSecret: TWITTER_CONSUMER_SECRET
    }
    const redirectUrl = 'http://localhost/twitter'
    auth(tokens, redirectUrl)
      .then(resp => console.log(resp))
      .catch(err => console.log(err))

Sources for assign MUST be an object

I'm getting a problem after attempting to invoke the rest.post() method to tweet some text.

The code for the method is
postTweet(){ var tokens= { consumer_key: 'xxx', consumer_secret: 'xxx', access_token: 'xxx', access_token_secret: 'xxx', }; const {rest} = twitter(tokens); var path = 'statuses/update'; var params = this.state.text; rest.post(path , params) .then(() => {console.log('Posted');}) .catch(console.error); }

image

Please help with uploading images not in Camera Roll

Hi, firstly I would like to say I really like this library and appreciate how well made it is.

The issue I'm having is that I don't know how to post a status with an image without using the camera roll. Is there anyway to get an image from a url on the internet and post that image to a twitter status along with some text? Please point me in the right direction, I couldn't find anything in your documentation.

Thank you so much for your time

App Rejected due to Twitter Auth - auth needs to occur without redirecting people to safari

Guideline 4.0 - Design


We noticed that the user is taken to Safari to sign in or register for an account, which provides a poor user experience.

Next Steps

To resolve this issue, please revise your app to enable users to sign in or register for an account in the app.

We recommend implementing the Safari View Controller API to display web content within your app. The Safari View Controller allows the display of a URL and inspection of the certificate from an embedded browser in an app so that customers can verify the webpage URL and SSL certificate to confirm they are entering their sign in credentials into a legitimate page.

Problems Uploading Images

Hello, i am trying to upload an image to Twitter using your library.
i did read your solution here but it does not work.
Having some more read into your code i understand that only the old method from here is supported and not the new one, but even so i could not upload an image.

I tried to implement the chunked method on my own, and started by doing something like
client.rest.post('media/upload', {command:"INIT", total_bytes:"70456", media_type:"image/jpeg"}).then((resolve) => { alert('media/upload '+ JSON.stringify(resolve)) console.log('done'); }).catch(console.error);
but nothing is returned. Still, if i use an alert after response.text() on raw.js of the included libraries i do get the response.

I am fairly new to React-Native (and JS) so, could ypu please provide a better example, or a way to actually retrieve the response there and chain it with the APPEND and FINISH methods?

Thanks in advance

Not able to retweet

I am using client.rest.post('statuses/retweet/:id', { id }) to retweet. But I get an error saying: No status found with { id: 0 }.

React native 0.63.2 Auth not working (Solved)

I found auth not working because of "url-search-params" package.
Go to node_modules\react-native-twitter\src\oauth\auth.js and replace everything with code below. It may not be most efficient but it works.

import {Linking} from 'react-native';

import URLSearchParams from 'url-search-params';

import request from './request';
import {query} from '../util';

function getRequestToken(tokens, callbackUrl, accessType) {
  const method = 'POST';
  const url = 'https://api.twitter.com/oauth/request_token';
  const body = accessType ? {x_auth_access_type: accessType} : {};
  return request(tokens, url, {method, body}, {oauth_callback: callbackUrl})
    .then((response) => response.text())
    .then((text) => {
      var regex = /[?&]([^=#]+)=([^&#]*)/g,
        url = '&' + text,
        params = {},
        match;
      while ((match = regex.exec(url))) {
        params[match[1]] = match[2];
      }
      return {
        requestToken: params['oauth_token'],
        requestTokenSecret: params['oauth_token_secret'],
      };
    });
}

function getAccessToken(
  {consumerKey, consumerSecret, requestToken, requestTokenSecret},
  oauthVerifier,
) {
  //console.log("came to getAccessToken")
  const method = 'POST';
  const url = 'https://api.twitter.com/oauth/access_token';
  return request(
    {
      consumerKey,
      consumerSecret,
      oauthToken: requestToken,
      oauthTokenSecret: requestTokenSecret,
    },
    url,
    {method},
    {oauth_verifier: oauthVerifier},
  )
    .then((response) => response.text())
    .then((text) => {
      var regex = /[?&]([^=#]+)=([^&#]*)/g,
        url = '&' + text,
        params = {},
        match;
      while ((match = regex.exec(url))) {
        params[match[1]] = match[2];
      }
      return {
        accessToken: params['oauth_token'],
        accessTokenSecret: params['oauth_token_secret'],
        id: params['user_id'],
        name: params['screen_name'],
      };
    });
}

const verifierDeferreds = new Map();

Linking.addEventListener('url', ({url}) => {
  const params = getJsonFromUrl(url);
  if (params['oauth_token'] && verifierDeferreds.has(params['oauth_token'])) {
    //console.log("inside")
    const verifierDeferred = verifierDeferreds.get(params['oauth_token']);
    verifierDeferreds.delete(params['oauth_token']);
    if (params['oauth_verifier']) {
      verifierDeferred.resolve(params['oauth_verifier']);
    } else {
      verifierDeferred.reject(new Error('denied'));
    }
  }
});

export default async function auth(
  tokens,
  callbackUrl,
  {accessType, forSignIn = false, forceLogin = false, screenName = ''} = {},
) {
  const usePin = typeof callbackUrl.then === 'function';
  const {requestToken, requestTokenSecret} = await getRequestToken(
    tokens,
    usePin ? 'oob' : callbackUrl,
    accessType,
  );
  //console.log("came here-->", requestToken, requestTokenSecret)
  Linking.openURL(
    `https://api.twitter.com/oauth/${
      forSignIn ? 'authenticate' : 'authorize'
    }?${query({
      oauth_token: requestToken,
      force_login: forceLogin,
      screen_name: screenName,
    })}`,
  );
  return getAccessToken(
    {...tokens, requestToken, requestTokenSecret},
    await (usePin
      ? callbackUrl
      : new Promise((resolve, reject) => {
          verifierDeferreds.set(requestToken, {resolve, reject});
        })),
  );
}

function getJsonFromUrl(url) {
  if (!url) url = location.href;
  var question = url.indexOf('?');
  var hash = url.indexOf('#');
  if (hash == -1 && question == -1) return {};
  if (hash == -1) hash = url.length;
  var query =
    question == -1 || hash == question + 1
      ? url.substring(hash)
      : url.substring(question + 1, hash);
  var result = {};
  query.split('&').forEach(function (part) {
    if (!part) return;
    part = part.split('+').join(' '); // replace every + with space, regexp-free version
    var eq = part.indexOf('=');
    var key = eq > -1 ? part.substr(0, eq) : part;
    var val = eq > -1 ? decodeURIComponent(part.substr(eq + 1)) : '';
    var from = key.indexOf('[');
    if (from == -1) result[decodeURIComponent(key)] = val;
    else {
      var to = key.indexOf(']', from);
      var index = decodeURIComponent(key.substring(from + 1, to));
      key = decodeURIComponent(key.substring(0, from));
      if (!result[key]) result[key] = [];
      if (!index) result[key].push(val);
      else result[key][index] = val;
    }
  });
  return result;
}

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.