kanonymtさんのブログ -3ページ目

kanonymtさんのブログ

ブログの説明を入力します。

思ったように動かず。。。以後、あれこれ格闘


直接的なサンプルや記事が本当に少なく、

下記OauthやTwitterAPI関連のサイトも確認。


PHPでTwitter APIのOAuthを使う方法まとめ
http://www.msng.info/archives/2010/01/twitter_api_oauth_with_php.php

PythonでYammerにアクセスしてみる その1
http://smartchamploo.blogspot.com/2011/05/pythonyammer-1.html#!/2011/05/pythonyammer-1.html

Twitter API を OAuth で認証するスクリプトを 0 から書いてみた
http://techno-st.net/2009/11/26/twitter-api-oauth-0.html


認証の流れや仕組みはざっくりとわかったが、

それを実現するための手段・手順が…

やはり実際に動くサンプルがほしい。

やっと一つ、ほぼそのままで動きそうなものがあったので、(php)

サンプルをダウンロードして、

index.phpに、

また改めてyammerにアプリ登録をし、

取得したConsumer_Key、Consumer_Secretを記述して、

phpの環境のあるレンタルサーバーにアップして動きをみてみる


Yammer API Example
http://www.tutorialjinni.com/2011/04/yammer-api-example.html


…が、、、


partiea4のブログ-002_2aAuthentication01.png

Token、Token_Secretは取得できたものの、
その次のAccessTokenで画面のようになり進まない。
(AuthCodeが取れていないためと思われる)

PHPのデバッグをしたいところではあるが、

今の主旨とは違ってしまうため、それは後回し。





■2.2Authentication


partiea4のブログ

Once the page has checked the user’s status, the user may need to be prompted to login.
(ログイン状況のチェックが終わったら、ログイン画面が表示される模様)


ペタ貼りしてalert文を追加

yam.login( function (response) {
if (response.authResponse) {
// user successfully logged in
alert('yam:logged in');
}
else {
// user cancelled login
alert('yam:NOT logged in');
}
});


Yammerこのページの後にあるように、
アプリ認証画面が表示されることを期待してアップするが、
ウンともスンともいわない(-_-;)。
alertも表示されないので、そもそもここを通っていない模様。


ここで結構ハマる…
よくわかっていない状態の人間だとこんなところでもつまづきます(; ;)


次に、ハマっていろいろ格闘した分を載せます。
(実際の手順とははずれますので、先に進みたい方は飛ばしてください)

アプリの登録が終わったので、
再びJavascriptのAPIのページの手順を進める


partiea4のブログ


■2.1■Authentication
The JavaScript SDK allows developers to share the logged in user state between yammer.com and their site. A Yammer user remains logged into the 3rd party site.

To find out the authentication status of the user call the getLoginStatus function. This answers the question “who is the current user?” by saying it's either: someone you don't know, someone you know and have interacted with and returns a session for them.
(yam.getLoginStatus関数で
ログインしているかの状況がわかる模様)


htmlにコードを追加して、alert文を入れて確認


yam.getLoginStatus( function(response) {
if (response.authResponse) {
// logged in and connected user, someone you know
alert('status:logged in');
}
else{
// no user session available, someone you don't know
alert('status:NOT logged in');
}
});



partiea4のブログ


ログインしていない旨のアラート表示がされるので、動いてはいる模様
(実際にクライアント上で、Yammerにログインしているいないにかかわらず
ここではelse文の方を通る)


※画面で更新日が表示されるのは、

ファイルの更新が確認できるようにjavascriptを追記しています。