Note: Most of the Article of this blog has taken from another reputated blogs,Websites so Author will not responsible for any Issue.

New Social API Web Application Toolkit for .NET Web Developers

Latest in this API

We've just published an update to our Web Application Toolkits! Here is a summary of web application toolkits:

Its totally free for .net developers.It help ASP.NET web developers complete common web development tasks and quickly add new features to your apps. Whether it's Bing Maps integration or adding social capabilities to your site, there's a toolkit for you. For the full list of Web Application Toolkits check out this website.

Summary:-

  1. Added a new Social API Web Application Toolkit
  2. Updated all the WATs to be compatible with Visual Studio 2010
Introducing the Social API Web Application Toolkit

image



As social networking Web sites are becoming more and more popular, users often want to access simultaneously the different networks they belong to from one only entry point. For example, one user might want to post the same message they are posting on your site also on Facebook, Twitter, MySpace and so on.

Although many of these social networks provide APIs for accessing their information, you might want to integrate your Web application with several social sites at the same time and be able to do this in a consistent manner, without having to go into numerous modifications in your code with each new social network that you want to incorporate.

This Web Application Toolkit provides a generic "Social Networks" API that allows connecting your Web application with different social networks and managing them through one entry point with a consistent set of methods. In the Toolkit you'll find examples of how to use the Social Networks API provided to connect a Web application with Facebook and Twitter, allowing you to manage the data provided by these networks in a generic way.

Please notice that this Toolkit includes examples only for reduced set of operations (mainly posting status updates) within the two social networks named before. Through this documentation you'll find instructions on how to extend this set into more operations and more social networks.

More Details:-

This toolkit comes with Facebook and Twitter Providers that allow you to perform tasks against different Social Network APIs in a common way.  For example, Facebook and Twitter do authentication in different ways which is a pain because you have to write different code for each network.  The Providers mean that you can call common methods and pass in which social networks you want to perform the action against – behind the scenes the providers call the appropriate methods against Facebook or Twitter to get the job done.  The provider model also makes it easy to extend the API to other Social Networks in the future – we've provided detailed instructions on how to do this in the documentation that comes with the toolkit download – it's in the "next steps" section.

  1. public ActionResult NetworkLogin(string providerName)
  2.         {
  3.             var social = new SocialProxy();
  4.             return this.Redirect(social.GetProvider(providerName).LoginUrl);
  5.         }

The code above shows how you use the SocialProxy class, included in the toolkit to get the login URL for the given social network.  In this example we then redirect the user to that URL instead of an MVC view in our application.

The Social Networks API checks if the user is already authenticated in the application and if not it authenticates him by using the FormsAuthentication.SetAuthCookie method. The API maintains a user repository with the account information for each user's social networks.

  1. public bool Login(string providerName, HttpContextBase httpContext)
  2.         {                        
  3.             var provider = this.GetProvider(providerName);
  4.             var identity = provider.GetLoginIdentity(httpContext);
  5.             
  6.             if (identity == null)
  7.             {
  8.                 return false;
  9.             }
  10.  
  11.             if (!httpContext.User.Identity.IsAuthenticated)
  12.             {
  13.                  var userId = this.usersRepository.FindIdentity(identity) ?? this.usersRepository.CreateUser(identity);
  14.                  FormsAuthentication.SetAuthCookie(userId, false);
  15.             }
  16.             else
  17.             {
  18.                  var userId = this.usersRepository.FindIdentity(identity);
  19.                  if (userId != httpContext.User.Identity.Name)
  20.                  {
  21.                      this.usersRepository.AssociateIdentity(httpContext.User.Identity.Name, identity);
  22.                  }
  23.             }
  24.  
  25.             return true;
  26.         }

Notice that new users do not need to create a separate account when registering on the Web application. The API stores the user's Facebook and Twitter account information, and creates a unique identifier on the user repository for that user to keep them associated.

The API stores the user internal identifier together with the login information for each of its associated social networks, by using the UsersRepository.AssociateIdentity method.