GithubHelp home page GithubHelp logo

daydayup9 / social_share Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexiscn/social_share

0.0 2.0 0.0 60 KB

social sharing for windows phone. Including Weibo, Tencent Weibo, Renren and QQZone

License: MIT License

social_share's Introduction

social share lib for windows phone

Social sharing for windows phone. Including Weibo, Tencent Weibo, Renren and QQZone and others maybe supported in future.

##Features## Saving your time sharing things(text or image or both text and image) to social using this sdk. Currently support following social networks:

Social Share use WebBrowser control to handle oauth2 authorizes and provides some useful usercontrol like:

  • AuthControl to handle oauth2 authorize
  • AccountControl to give user to manage their accounts
  • ShareControl to send share text and image

How to Use?

  1. download proper dll and add dll reference to your main windows phone project.
  2. define global variables in App.xaml.cs file
	public class App
	{
		/// <summary>
		/// current socail type
		/// </summary>
		public static SocialType CurrentSocialType { get; set; }
		
		/// <summary>
		/// if login from account page, then we should goback
		/// </summary>
		public static bool IsLoginGoBack { get; set; }
		
		/// <summary>
		/// shared text
		/// </summary>
		public static string Statues { get; set; }
		
		/// <summary>
		/// shared image
		/// </summary>
		public static WriteableBitmap ShareImage { get; set; }
	}
  1. add new Class named Constants, and fill social keys and secrets in this Class
	public class Constants
	{
	    public const string SHARE_IMAGE = "share.jpg";
	
	    public static ClientInfo GetClient(SocialType type)
	    {
	        ClientInfo client = new ClientInfo();
	        switch (type)
	        {
	            case SocialType.Weibo:
	                client.ClientId = "YOUR_WEIBO_CLIENT_ID";
	                client.ClientSecret = "YOUR_WEIBO_CLIENT_SECRET";
	                //client.RedirectUri = "http://weibo.com/";//if not set,left this property empty
	                break;
	            case SocialType.Tencent:
	                client.ClientId = "";
	                client.ClientSecret = "";
	                break;
	            case SocialType.Renren:
	                client.ClientId = "";
	                client.ClientSecret = "";
	                break;
	            default:
	                break;
	        }
	        return client;
	    }
	}
  1. add authorize page named SocialLoginPage.xaml to place auth control. XAML looks like:
	<!--LayoutRoot is the root grid where all page content is placed-->
	<Grid x:Name="LayoutRoot" Background="Transparent">       
	</Grid>
  1. add following method in SocialLoginPage.xaml.cs and call it in page constructor:
	private void LoadLoginControl()
	{
	    AuthControl control = new AuthControl();
	    var type = App.CurrentSocialType;
	    control.SetData(type, Constants.GetClient(type));
	    control.action += (p) =>
	    {
	        if (App.IsLoginGoBack)
	        {
	            Deployment.Current.Dispatcher.BeginInvoke(delegate
	            {
	                if (NavigationService.CanGoBack)
	                {
	                    NavigationService.GoBack();
	                }
	            });
	        }
	        else
	        {
	            _isClearBackStack = true;
	            Deployment.Current.Dispatcher.BeginInvoke(delegate
	            {
	                NavigationService.Navigate(new Uri("/SocialSendPage.xaml", UriKind.Relative));
	            });
	        }
	    };
	    this.LayoutRoot.Children.Add(control);
	}
  1. overwrite page OnNavigatedFrom event to clear history stack page.
	protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
	{
	    if (_isClearBackStack)
	    {
	        if (NavigationService.CanGoBack)
	        {
	            Deployment.Current.Dispatcher.BeginInvoke(delegate
	            {
	                NavigationService.RemoveBackEntry();
	            });
	        }
	    }
	    base.OnNavigatedFrom(e);
	}
  1. add send status page named SocialSendPage.xaml. This got an applicationbar in page to fire send method.
	private void Send()
	{
	    this.Focus();
	    ApplicationBar.IsVisible = false;
	
	    grid.Visibility = System.Windows.Visibility.Visible;
	    tbk_busy.Text = "sending...";
	    if (sb_busy != null)
	    {
	        sb_busy.Begin();
	    }
	    SocialAPI.Client = Constants.GetClient(App.CurrentSocialType);
	
	    SocialAPI.UploadStatusWithPic(App.CurrentSocialType, ptb_status.Text, Constants.SHARE_IMAGE, (isSuccess, err) =>
	    {
	        Deployment.Current.Dispatcher.BeginInvoke(delegate
	        {
	            ApplicationBar.IsVisible = true;
	            grid.Visibility = System.Windows.Visibility.Collapsed;
	            if (isSuccess)
	            {
	                MessageBox.Show("success");
	                if (NavigationService.CanGoBack)
	                {
	                    NavigationService.GoBack();
	                }
	            }
	            else
	            {
	                MessageBox.Show("failed");
	            }
	        });
	    });
	}
  1. If you want your user to manage their social accounts, you can also add an account management page named AccountPage.xaml
	<!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <social:AccountControl x:Name="accountControl" />
    </Grid>
	public AccountPage()
	{
	    InitializeComponent();
	    accountControl.BindAction = ((p) =>
	    {
	        App.IsLoginGoBack = true;
	        App.CurrentSocialType = p;
	        NavigationService.Navigate(new Uri("/SocialLoginPage.xaml", UriKind.Relative));
	    });
	}

You can view full source code in this demo app.

Contact me

If you have any question, please contact me via Weibo or Twitter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.