ユーザーのウォールに投稿できるように、Facebook oAuth を Phonegap 2.3.0 アプリケーションと統合しようとしています。私はここからライブラリを使用することができます: Phonegap oauthにいくつかの変更を加えて、childbrowser が InAppBrowser と呼ばれるようになり、コア Phonegap の一部になりました - 以下を参照してください。
function FBConnect()
{
this.facebookkey = 'facebook';
this.childBrowser = null;
}
FBConnect.prototype.connect = function(options)
{
this.client_id = options.consumerKey;
this.client_secret = options.consumerSecret
this.redirect_uri = options.callbackUrl;
oauth = OAuth(options);
var authorize_url = "https://m.facebook.com/dialog/oauth?";
authorize_url += "client_id=" + this.client_id;
authorize_url += "&redirect_uri=" + this.redirect_uri;
authorize_url += "&display=touch";
authorize_url += "&response_type=token";
authorize_url += "&type=user_agent";
authorize_url += "&scope=email,read_stream,publish_stream";
var self = this;
self.childBrowser = window.open(authorize_url, '_blank', 'location=no');
self.childBrowser.addEventListener('loadstart', function(event){ console.log('event fired: '+event);self.onLocationChange(event.url);});
}
FBConnect.prototype.onLocationChange = function(loc)
{
console.log("onLocationChange : " + loc);
// If user hit "No, thanks" when asked to authorize access
if (loc.indexOf("login_success.html?error_reason=user_denied") >= 0) {
this.childBrowser.close();
return;
}
// here we get the code
if (loc.indexOf("access_token") >= 0) {
var access_token = loc.match(/access_token=(.*)$/)[1];
console.log("facebook token" + access_token);
window.localStorage.setItem(window.plugins.fbConnect.facebookkey, access_token);
this.childBrowser.close();
this.onConnect();
}
}
InAppBrowser を開いて、ユーザーを認証ページに送ることができます。ユーザーはまず自分の Facebook アカウントでログインし、次にアプリケーション ページを表示します。[OK] をクリックすると、アクセス権を付与できるようになり、続いて権限画面が表示されます。次に、ユーザーはアプリにアクセス許可を付与し、http: //www.facebook.com/connect/login_success.htmlとして設定された callbackUrl に送信されます。ただし、この段階では、トークンがクエリ パラメータとして URL に添付されることを期待しています。URLには何もありません。
何か不足していますか?