Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Getting email for current user #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.twitter.sdk.android.core.DefaultLogger;
import com.twitter.sdk.android.core.Result;
import com.twitter.sdk.android.core.Twitter;
import com.twitter.sdk.android.core.TwitterCore;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.twitter.sdk.android.core.TwitterAuthToken;
import com.twitter.sdk.android.core.TwitterConfig;
Expand Down Expand Up @@ -93,6 +94,24 @@ public void failure(TwitterException exception) {

}

@ReactMethod
public void getEmailForCurrentUser(final Promise promise) {
TwitterSession twitterSession = TwitterCore.getInstance().getSessionManager().getActiveSession();
TwitterAuthClient authClient = new TwitterAuthClient();
authClient.requestEmail(twitterSession, new Callback < String > () {
@Override
public void success(Result < String > result) {
promise.resolve(result.data);
}

@Override
public void failure(TwitterException exception) {
promise.reject(TAG, exception.getMessage());
}
});
}


@Override
public void onHostResume() {
if (currentData != null) {
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
platform :ios, '9.0'

target 'example' do
pod 'TwitterKit', '3.1.1'
pod 'TwitterKit', '3.4.0'
end
4 changes: 2 additions & 2 deletions example/ios/example/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <TwitterKit/TwitterKit.h>
#import <TwitterKit/TWTRKit.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

NSURL *jsCodeLocation;

jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
Expand Down
15 changes: 14 additions & 1 deletion ios/TPSTwitterModule/TPSTwitterModule.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "TPSTwitterModule.h"
#import <TwitterKit/TwitterKit.h>
#import <TwitterKit/TWTRKit.h>
#import <Social/Social.h>
#import <React/RCTUtils.h>
#import "OAuthCore.h"
Expand Down Expand Up @@ -130,6 +130,19 @@ - (NSDictionary *)errorCodesMap {
}
}

RCT_EXPORT_METHOD(getEmailForCurrentUser:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
TWTRAPIClient *client = [TWTRAPIClient clientWithCurrentUser];
[client requestEmailForCurrentUser:^(NSString * _Nullable email, NSError * _Nullable error) {
if (error) {
NSError *rejectError = [self buildCannotLoadAccountErrorWithUnderlyingError:error];
reject([self buildErrorCodeForError:rejectError], rejectError.localizedDescription, rejectError);
} else {
resolve(email);
}
}];
}

#pragma mark - NSError

- (NSError *)buildErrorWithCode:(NSInteger)code localizedDescription:(NSString *)localizedDescription {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tipsi-twitter",
"version": "2.1.1",
"version": "2.1.2",
"description": "Twitter sdk for react-native",
"main": "src/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions scripts/post-link-ios.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
Dir.chdir('ios')

@podfile_path = Pathname.pwd + 'Podfile'
@pod_dep_kit = " pod 'TwitterKit', '3.1.1'\n"
@pod_dep_core = " pod 'TwitterCore', '3.0.1'\n"
@pod_dep_kit = " pod 'TwitterKit', '3.4.0'\n"
@pod_dep_core = " pod 'TwitterCore', '3.2.0'\n"

@project_paths= Pathname.pwd.children.select { |pn| pn.extname == '.xcodeproj' }
raise 'No Xcode project found' unless @project_paths.length > 0
Expand Down