Twitter integration on website

I am trying to get a site to connect to my Twitter account so that I can display tweets on my website. I can get the application to work when you connect through OAuth authentication and asks if I want to allow the application.

What I want to do is that this is my own Twitter account, I want to be able to log in without having to do this every time. I want the website to send my credentials so that the user simply views the page and can view tweets. Is it possible?

+3
source share
3 answers

. , IConsumerTokenManager. , , ConsumerKey, ConsumerSecret GetTokenSecret ( ).

#region Namespaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages; 
#endregion

namespace BingMapTest
{
    public class ConsumerTokenManager : IConsumerTokenManager
    {
        public string ConsumerKey
        {
            get { return "xxxxxxxx"; }
        }

        public string ConsumerSecret
        {
            get { return "xxxxxxxx"; }
        }

        public string GetTokenSecret(string token)
        {
            return "xxxxxxxx";
        }

        public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret)
        {
            throw new NotImplementedException();
        }

        public TokenType GetTokenType(string token)
        {
            throw new NotImplementedException();
        }

        public bool IsRequestTokenAuthorized(string requestToken)
        {
            throw new NotImplementedException();
        }

        public void StoreNewRequestToken(UnauthorizedTokenRequest request, ITokenSecretContainingMessage response)
        {
            throw new NotImplementedException();
        }
    }
}

, Page_Load ConsumerTokenManager:

protected void Page_Load(object sender, EventArgs e)
        {
            ITwitterAuthorization auth;

            ConsumerTokenManager tokenManager = new ConsumerTokenManager();

            auth = new WebOAuthAuthorization(tokenManager, "accessToken");
            auth.UseCompression = true;

            // For Twitter
            using (var twitterCtx = new TwitterContext(auth, "https://api.twitter.com/1/", "https://search.twitter.com/"))
            {                   
                // Whatever authorization module we selected... sign on now.  
                try
                {
                    auth.SignOn();
                }
                catch (OperationCanceledException)
                {
                    return;
                }
            }
        }

, , - .

+1

, , :

http://twitter.com/statuses/user_timeline/mytwittername.json?callback=twitterCallback2&count=4

4 ,

+1

oauth.

, API oauth . , Twitter ( ), .

- , ..

0
source

Source: https://habr.com/ru/post/1752490/


All Articles