|
@@ -5,30 +5,20 @@ import Twit from "twit";
|
|
|
|
|
|
@Injectable()
|
|
@Injectable()
|
|
export class TwitterApiProvider {
|
|
export class TwitterApiProvider {
|
|
- consumer_key: string = "UxZkbKotkr8Uc6seupnaZ1kDE";
|
|
|
|
- consumer_secret: string =
|
|
|
|
- "fEAas8iugR60FOEXsFG0iajq6oyfIIXRBVMlTgWxBd1stWIKHq";
|
|
|
|
- access_token_key: string;
|
|
|
|
- access_token_secret: string;
|
|
|
|
- client;
|
|
|
|
|
|
+ client: Twit;
|
|
|
|
|
|
constructor(public http: HttpClient, private storage: Storage) {
|
|
constructor(public http: HttpClient, private storage: Storage) {
|
|
- Promise.all([
|
|
|
|
- this.storage.get("accessTokenKey"),
|
|
|
|
- this.storage.get("accessTokenSecret")
|
|
|
|
- ]).then(values => {
|
|
|
|
- this.access_token_key = values[0];
|
|
|
|
- this.access_token_secret = values[1];
|
|
|
|
- this.initApi();
|
|
|
|
- });
|
|
|
|
|
|
+ this.initApi();
|
|
}
|
|
}
|
|
|
|
|
|
- private initApi() {
|
|
|
|
|
|
+ private async initApi() {
|
|
|
|
+ const access_token_key = await this.storage.get("accessTokenKey");
|
|
|
|
+ const access_token_secret = await this.storage.get("accessTokenSecret");
|
|
this.client = new Twit({
|
|
this.client = new Twit({
|
|
- consumer_key: this.consumer_key,
|
|
|
|
- consumer_secret: this.consumer_secret,
|
|
|
|
- access_token: this.access_token_key,
|
|
|
|
- access_token_secret: this.access_token_secret,
|
|
|
|
|
|
+ consumer_key: "UxZkbKotkr8Uc6seupnaZ1kDE",
|
|
|
|
+ consumer_secret: "fEAas8iugR60FOEXsFG0iajq6oyfIIXRBVMlTgWxBd1stWIKHq",
|
|
|
|
+ access_token: access_token_key,
|
|
|
|
+ access_token_secret: access_token_secret,
|
|
timeout_ms: 60 * 1000 // optional HTTP request timeout to apply to all requests.
|
|
timeout_ms: 60 * 1000 // optional HTTP request timeout to apply to all requests.
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -88,4 +78,23 @@ export class TwitterApiProvider {
|
|
public async tweet(status) {
|
|
public async tweet(status) {
|
|
return await this.client.post("statuses/update", { status: status });
|
|
return await this.client.post("statuses/update", { status: status });
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public async fetchFriends(userId) {
|
|
|
|
+ let friends = [];
|
|
|
|
+ let cursor = -1;
|
|
|
|
+
|
|
|
|
+ while (cursor != 0) {
|
|
|
|
+ const res = await this.client.get("friends/list", {
|
|
|
|
+ user_id: userId,
|
|
|
|
+ count: 200,
|
|
|
|
+ include_user_entities: false,
|
|
|
|
+ cursor: cursor
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ cursor = res.data["next_cursor"];
|
|
|
|
+ friends = friends.concat(res.data["users"]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return friends;
|
|
|
|
+ }
|
|
}
|
|
}
|