예제 #1
0
        private TwitterContext GetTwitterContext(string serializeInfo = "")
        {
            TwitterData.TwitterUser user = JsonConvert.DeserializeObject <TwitterData.TwitterUser>(serializeInfo);
            var auth = new XAuthAuthorizer()
            {
                //CredentialStore = new InMemoryCredentialStore
                //{
                //	ConsumerKey = "YVgafJLg6figpxcFTx9oBhXDw",
                //	ConsumerSecret = "AdNdiuHSHIf5hN6HWnVrC9u6bnW3vVirjEhAFrfabacPIQdh98",
                //	OAuthToken = "3620214675-KzcSqmYy131LlcQGe8nOptxCdQCBP8ajPYXYwvl",
                //	OAuthTokenSecret = "GycvXtklGfaYz1WjOINEhkmZr6OwGDz38SUX68iCMWv9f",
                //	ScreenName = "bogdanm__",
                //	UserID = 3620214675
                //},
                CredentialStore = new InMemoryCredentialStore
                {
                    ConsumerKey      = "YVgafJLg6figpxcFTx9oBhXDw",
                    ConsumerSecret   = "AdNdiuHSHIf5hN6HWnVrC9u6bnW3vVirjEhAFrfabacPIQdh98",
                    OAuthToken       = "3620214675-KzcSqmYy131LlcQGe8nOptxCdQCBP8ajPYXYwvl",
                    OAuthTokenSecret = "GycvXtklGfaYz1WjOINEhkmZr6OwGDz38SUX68iCMWv9f",
                    ScreenName       = user == null ? String.Empty : user.ScreenName,
                    UserID           = user == null ? 0 : user.UserID
                },
            };

            auth.AuthorizeAsync();

            var ctx = new TwitterContext(auth);

            return(ctx);
        }
예제 #2
0
        private async Task <DataIUser> LoginToTwitter()
        {
            DataIUser resultUser = null;

            LinqToTwitter.User twitterUser = null;
            try
            {
                TaskCompletionSource <int> ts = new TaskCompletionSource <int>();

                var auth = new OAuth1Authenticator(
                    consumerKey: "YVgafJLg6figpxcFTx9oBhXDw",
                    consumerSecret: "AdNdiuHSHIf5hN6HWnVrC9u6bnW3vVirjEhAFrfabacPIQdh98",
                    requestTokenUrl: new Uri("https://api.twitter.com/oauth/request_token"),
                    //https://api.twitter.com/oauth/authorize
                    authorizeUrl: new Uri("https://api.twitter.com/oauth/authorize"),
                    accessTokenUrl: new Uri("https://api.twitter.com/oauth/access_token"),
                    callbackUrl: new Uri("https://oauth.vk.com/blank.html"));

                auth.AllowCancel = true;

                auth.Completed += (s, ee) =>
                {
                    if (!ee.IsAuthenticated)
                    {
                        ts.SetResult(0);
                        return;
                    }

                    var twitterCtx = GetTwitterContext();

                    var accounts =
                        from acct in twitterCtx.Account
                        where acct.Type == AccountType.VerifyCredentials
                        select acct;

                    LinqToTwitter.Account account = accounts.SingleOrDefault();

                    twitterUser = account.User;

                    #region unused requests

                    //var searchResponses = (from search in ctx.Search
                    //											 where search.Type == SearchType.Search
                    //											 && search.Query == searchText
                    //											 select search).SingleOrDefault();

                    //var tweets = from tweet in searchResponses.Statuses
                    //						 select new Message
                    //						 {
                    //							 Value = tweet.Text,
                    //							 Id = tweet.TweetIDs,
                    //							 ImageUri = tweet.User.ProfileImageUrl,
                    //							 UserName = tweet.User.ScreenNameResponse,
                    //							 Name = tweet.User.Name,
                    //							 CreatedAt = tweet.CreatedAt,
                    //							 ReTweets = tweet.RetweetCount,
                    //							 Favorite = tweet.FavoriteCount.Value
                    //						 };

                    //var followers = (from follower in twitterCtx.Friendship
                    //								 where follower.Type == FriendshipType.FollowersList &&
                    //											 follower.UserID == "3620214675"
                    //								 select follower).SingleOrDefault();

                    #endregion

                    string uid       = twitterUser.UserIDResponse;
                    string firstName = twitterUser.ScreenNameResponse;

                    TwitterData.TwitterUser twUser = new TwitterData.TwitterUser();
                    twUser.ConsumerKey      = twitterCtx.Authorizer.CredentialStore.ConsumerKey;
                    twUser.ConsumerSecret   = twitterCtx.Authorizer.CredentialStore.ConsumerSecret;
                    twUser.OAuthToken       = twitterCtx.Authorizer.CredentialStore.OAuthToken;
                    twUser.OAuthTokenSecret = twitterCtx.Authorizer.CredentialStore.OAuthTokenSecret;

                    twUser.UserID     = ulong.Parse(uid);
                    twUser.ScreenName = firstName;

                    resultUser = new User()
                    {
                        FirstName     = firstName,
                        Uid           = uid,
                        SerializeInfo = JsonConvert.SerializeObject(twUser),
                        SocialNetwork = enSocialNetwork.Twitter
                    };

                    ts.SetResult(0);
                };

                var intent = auth.GetUI(Forms.Context);
                Forms.Context.StartActivity(intent);
                await ts.Task;
            }
            catch (Exception)
            {
            }
            return(resultUser);
        }