新浪微博开放平台SDK for WinRT

这是什么

新浪微博开放平台API for WinRT 是一个基于新浪微博开放平台第二版API接口进行封装的一个针对Windows 8 平台(Xaml 应用)的软件开发包。本SDK有助于.Net平台开发人员在 Windows 8 移动平台上快速简便地开发微博相关应用。

 

SDK 中内置了应用授权页面,只需调用 SDK 的 AuthenticateAsync 即可。

public class LoginViewModel : SinaWeibo_Win8AppStore.Common.BindableBase
{
    private const string AppKey = "967389259";
    private const string AppSecret = "001379b11292669a5399131cfc5b806d";
    private const string Callback = "http://JDCB.com";

    public async Task<WeiboClientV2> LoginAsync()
    {
        var weibo = new SinaWeiboClientV2.WeiboClientV2();
        weibo.Initialize(AppKey, AppSecret, Callback);

        var json = Windows.Storage.ApplicationData.Current.LocalSettings.Values["AccessToken"] as string;
        if (!string.IsNullOrEmpty(json)) 
        {
            weibo.AccessToken = await JsonConvert.DeserializeObjectAsync<OAuthAccessToken>(json);
        }
        
        if (weibo.AccessToken == null)
        {
            // 认证
            await weibo.AuthenticateAsync();
        }
        // 授权
        await weibo.AuthorizeAccessAsync(System.Threading.CancellationToken.None);
        Windows.Storage.ApplicationData.Current.LocalSettings.Values["AccessToken"] = 
            await JsonConvert.SerializeObjectAsync(weibo.CurrentAuthToken.ContextData["AccessToken"]);

        return weibo;
    }
}

Last edited Jan 7, 2013 at 2:00 AM by FelixFang, version 4

Comments

No comments yet.