No.1207 設定画面

移動前ブクマページ: https://b.hatena.ne.jp/entry/s/elve.hateblo.jp/entry/2017/04/19/195704

何人の読者に云々

かんどーさんとこの記事読んでピンと来なかったwwww
私は書きたいこと書いてるだけだからなぁ~っとw

今日できたこと

f:id:elve:20170419195215p:plain
「コード取得」を押す→はてなのコードを取得する画面をブラウザで開く
テキストボックスにコードを入れて「スタート」を押す
アイコンとブックマークURLが表示される

参考

[C#] DynamicJSONを利用したJSONのパース
を参考にdllを入れたNuGetで入れたからdllはいらんかった(^_^;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using AsyncOAuth;
using Codeplex.Data;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private RequestToken requestToken;
private async void button1_Click(object sender, EventArgs e)
{
//登録
//OAuth Consumer Keyプライベート ************
//OAuth Consumer Secretプライベート ************
//OAuth認証URL
//Temporary Credential Request URL    https://www.hatena.com/oauth/initiate
//Resource Owner Authorization URL(PC)   https://www.hatena.ne.jp/oauth/authorize
//Token Request URL https://www.hatena.com/oauth/token
var authorizer = new OAuthAuthorizer("************", "************");
var callbackUri = "oob";
var requestTokenResponse = await authorizer.GetRequestToken(
"https://www.hatena.com/oauth/initiate",
new[]
{
new KeyValuePair<string, string>(
"oauth_callback",
callbackUri
)
},
new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>(
"scope",
"read_public,write_public,read_private"
)
})
);
requestToken = requestTokenResponse.Token;
var authorizeUrl = authorizer.BuildAuthorizeUrl(
"https://www.hatena.ne.jp/touch/oauth/authorize",
requestToken);
//"https://dobon.net"を標準のブラウザで開いて表示する
System.Diagnostics.Process.Start(authorizeUrl);
}
private async void button2_Click(object sender, EventArgs e)
{
var pinCode = this.textBox1.Text;
var authorizer = new OAuthAuthorizer("************", "************");
try
{
// get access token
var accessTokenResponse = await authorizer.GetAccessToken("https://www.hatena.com/oauth/token", requestToken, pinCode);
// save access token.
var accessToken = accessTokenResponse.Token;
Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));
Debug.WriteLine("Key:" + accessToken.Key);
Debug.WriteLine("Secret:" + accessToken.Secret);
Properties.Settings.Default.oauth_token = accessToken.Key;
Properties.Settings.Default.oauth_token_secret = accessToken.Secret;
var test= new HatenaClient ("************", "************",accessToken);
var testjaon = await test.GetMy();
Debug.WriteLine("test: " + testjaon);
var json = DynamicJson.Parse(testjaon);
this.pictureBox1.ImageLocation = json.profile_image_url;
Properties.Settings.Default.url_name = json.url_name;
Properties.Settings.Default.display_name = json.display_name;
this.textBox2.Text = "http://b.hatena.ne.jp/" + Properties.Settings.Default.url_name;
}
catch
{
MessageBox.Show("コードが間違っているようです。再度コピーしてみてください");
}
}
}
}

どのくらい面白かった?

星を押して送信してね

平均 0 / 5. Vote count: 0

是非フォローしてください

最新の情報をお伝えします

2件のコメント

  • うーん、データの制御と画面の制御分けた方がいいらしいのだけどねぇ(^_^;

  • クラス分けたら同期がうまく取れなくなった(´;ω;`)

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です