Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(twitter-signin): README improvements #430

Merged
merged 2 commits into from
Feb 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
chore: update
  • Loading branch information
Ombuweb committed Feb 9, 2023
commit 57c2f1f32bc98592f609c62e0e6e32b46a4c2202
99 changes: 60 additions & 39 deletions packages/twitter/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @nativescript/twitter

A plugin that allows you to authenticate a user with their Twitter account.
<!-- TODO: Add more descriptions -->
## Contents

* [Installation](#installation)
* [Prerequisites](#prerequisites)
* [Usage](#usage)
* [Initializing Twitter Sign-in](#initializing-twitter-sign-in)
* [TwitterSignIn](#twittersignin)
* [logIn()](#login)
* [getCurrentUser()](#getcurrentuser)
* [logOut()](#logout)
* [License]

## Installation

Expand All @@ -9,18 +22,10 @@ npm install @nativescript/twitter

## Prerequisites

Go to [Twitter Apps](https://apps.twitter.com/) to create your app so that you can obtain the API key and secret. Note:

- Remember to set a Callback Url, whatever will work
- By default, Twitter won't allow you to grab a user's email. You first have to request for user's permission for your app to retrieve their email.

Here is what callbacks would look like:

![callback screenshot](https://raw.githubusercontent.com/NativeScript/plugins/main/packages/twitter/assets/images/callback.png)

## Usage
- Go to [Twitter Apps](https://apps.twitter.com/) and create your app to obtain the API key and secret.

### iOS
- Set a Callback Url with the `Twitter.callback` property. Whatever will work.
For iOS, add the following code to the `App_Resources/ios/Info.plist` file, and replace the `yourscheme` text with your URL.

```xml
<key>CFBundleURLTypes</key>
Expand All @@ -33,14 +38,29 @@ Here is what callbacks would look like:
</dict>
</array>
```
- Request for the user's permission for your app to retrieve their email. By default, Twitter won't allow you to grab a user's email.

Here is what callbacks would look like:

![callback screenshot](https://raw.githubusercontent.com/NativeScript/plugins/main/packages/twitter/assets/images/callback.png)

## Usage

### Initializing Twitter Sign-in

To set up Twitter Sign in, call the [Twitter class's](#twitter) [init()](#init) method passing it the consumer key and the consumer secret.

```ts
import { Twitter, TwitterSignIn } from '@nativescript/twitter';

Twitter.callback = 'yourscheme://';

Twitter.init(TWITTER_COMSUMER_KEY, TWITTER_CONSUMER_SECRET);
Twitter.init(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
```
### Sign in a user
To sign a user in, call the [logIn()](#login) method on the [TwitterSignIn](#twittersignin) class.

```ts
TwitterSignIn.logIn()
.then((session) => {
// session.authToken
Expand All @@ -49,22 +69,28 @@ TwitterSignIn.logIn()
.catch((e) => {});
```
## API

### Twitter

#### callback
```ts
Twitter.callback = "the callback"
Twitter.callback = "the callback url"
```

The callback URL

---
#### init()
```ts
Twitter.init(consumerKey: string, consumerSecret: string)
Twitter.init(consumerKey, consumerSecret)
```
Initializes the Twitter authentification with the specified key and secret.

| Parameter | Type | Description
|:---------|:-----|:-----------
| `consumerKey` | `string` |
| `consumerSecret` | `string` |

| Parameter | Type
|:---------|:-----
| `consumerKey` | `string`
| `consumerSecret` | `string`

----
### TwitterSignIn
Expand All @@ -77,27 +103,26 @@ TwitterSignIn.logIn().then((session: Session) =>{

})
```
### Session

---
#### logOut()

```ts
TwitterSignIn.logIn()
```
{
static logIn(): Promise<Session>;
static logOut();
static getCurrentUser(): Promise<TwitterUser>
| Property | Type | Description
|:---------|:-----|:-----------
| `authToken` | `string` | _readonly_
| `authTokenSecret` | `string` | _readonly_
| `userName` | `string` | _readonly_
| `userId` | `string` | _readonly_
| `ios` | `any` | _readonly_
| `android` | `any` | _readonly_

---
#### getCurrentUser()
```ts
TwitterSignIn.getCurrentUser().then((user: TwitterUser) =>{

}).catch((err) =>{

})
```

---
### TwitterUser

Expand All @@ -112,17 +137,13 @@ TwitterSignIn.getCurrentUser().then((user: TwitterUser) =>{
| `screenName` | `string` | _readonly_
| `userId` | `string` | _readonly_

### Session

| Property | Type | Description
|:---------|:-----|:-----------
| `authToken` | `string` | _readonly_
| `authTokenSecret` | `string` | _readonly_
| `userName` | `string` | _readonly_
| `userId` | `string` | _readonly_
| `ios` | `any` | _readonly_
| `android` | `any` | _readonly_
---
#### logOut()

```ts
TwitterSignIn.logIn()
```
---
## License

Apache License Version 2.0