gpt4 book ai didi

javascript - 从 inappbrowser 检索数据

转载 作者:行者123 更新时间:2023-11-29 21:29:36 25 4
gpt4 key购买 nike

我目前正在构建 Ionic 混合应用程序。

不幸的是,在 Facebook 注册过程中,我无法访问请求的响应数据。

我们想从 inappbrowser 中检索数据,并使用 Cordova 的 inappbrowser 进行回调。不幸的是我们不能。实现这一目标的最佳方法是什么?

function InAppBrowser($scope, $cordovaInAppBrowser, $rootScope, $http, $window) {

var durr;

$scope.facebook = facebook;
$scope.foobar = foobar;

function facebook() {

var options = {
location: 'no',
clearcache: 'yes',
toolbar: 'no'
};

durr = $cordovaInAppBrowser.open('https://www.facebook.com/dialog/oauth?scope=email,public_profile,user_friends,user_likes,user_photos,user_posts&client_id={client_id}&redirect_uri={callback_url}', '_blank', options)
.then(function(e) {
console.log(e);
})
.catch(function(e) {
console.log(e);
});

$rootScope.$on('$cordovaInAppBrowser:loadstop', function(e, event) {
$cordovaInAppBrowser.executeScript(
{ code: "localStorage.setItem('hurr', document.body.innerHTML)" },
function(data) {
console.log(data);
});
});
}

function foobar() {
console.log(durr);
// console.log(durr.localStorage.getItem('hurr'));
}
}

最佳答案

我不将此用于 Facebook,而是用于插件 Oauth。此插件使用 InAppBrowser:“https://github.com/nraboy/ng-cordova-oauth/blob/master/README.md”。使用起来非常简单。

$cordovaOauth.facebook("Your client id", "scope", "options").then(function (result) {
Console.log(JSON.stringify(result);
// Get the information about the user's account
// See more at https://developers.facebook.com/docs/graph-api/reference/v2.2/user
$http.get("https://graph.facebook.com/v2.2/me", {
params: {
access_token: "your token",
fields: "id,last_name,first_name,gender,picture,birthday,location,email",
format: "json"
}
}).then(function (result) {
/** your code **/
}

关于javascript - 从 inappbrowser 检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36721613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com