我有一个cordova应用程序,可用于Facebook等外部服务。在某些情况下,应用程序将在应用内浏览器中打开facebook.com以显示帖子或消息。但是当导航到Facebook.com/post / ...时,通常会要求用户再次登录; webview未获得授权......
对于已获得授权的应用,有什么方法可以将Facebook身份验证令牌以某种方式注入Web视图(Cookie?)以避免登录屏幕?
感谢。
答案 0 :(得分:1)
如果您正在使用InAppBrowser插件,则可以从Facebook登录中获取该网址。 Facebook身份验证令应该是其中的一部分。
类似于此处发生的事情(OpenFB):
/**
* Called either by oauthcallback.html (when the app is running the browser) or by the loginWindow loadstart event
* handler defined in the login() function (when the app is running in the Cordova/PhoneGap container).
* @param url - The oautchRedictURL called by Facebook with the access_token in the querystring at the ned of the
* OAuth workflow.
*/
function oauthCallback(url) {
// Parse the OAuth data received from Facebook
var queryString,
obj;
loginProcessed = true;
if (url.indexOf("access_token=") > 0) {
queryString = url.substr(url.indexOf('#') + 1);
obj = parseQueryString(queryString);
tokenStore['fbtoken'] = obj['access_token'];
if (loginCallback) loginCallback({status: 'connected', authResponse: {token: obj['access_token']}});
} else if (url.indexOf("error=") > 0) {
queryString = url.substring(url.indexOf('?') + 1, url.indexOf('#'));
obj = parseQueryString(queryString);
if (loginCallback) loginCallback({status: 'not_authorized', error: obj.error});
} else {
if (loginCallback) loginCallback({status: 'not_authorized'});
}
}