gpt4 book ai didi

android - 如何在 ionic 框架中获取用户数据(公共(public)资料和电子邮件)

转载 作者:行者123 更新时间:2023-11-30 00:59:56 25 4
gpt4 key购买 nike

我正在开发 Ionic 移动应用程序。创建 Facebook 登录按钮(工作正常)后,我想获取用户数据(我的数据库的公开个人资料和电子邮件。

我的索引.html

<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/angular-sanitize/angular-sanitize.min.js"></script>
<script src="js/ng-cordova.min.js"></script><script src="lib/ng-cordova-oauth/dist/ng-cordova-oauth.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- your app's js -->

<script src="js/app.js"></script>
<script src="js/services.js"></script>
<script src="js/controllers.js"></script>

Controller.js

.controller('login',['$scope','myService','$location','$state','$timeout',function($scope,myService,$location,$state,$timeout)
{
$scope.fbLogin = function ($cordovaOauth,$http) {
facebookLogin(window.cordovaOauth, window.http);
console.log(fbLogin);
}
}])

应用程序.js

var app = angular.module('starter', ['ionic', 'starter.controllers','starter.services','ngSanitize',  'ngCordova', 'ngCordovaOauth']);

请告诉我哪里做错了。有时我会收到 $cordovaOauth 错误。模块化未注入(inject)。

最佳答案

function login(){
facebookLogin(window.cordovaOauth, window.http);
}

function facebookLogin($cordovaOauth, $http)
{
$cordovaOauth.facebook("1633195863589792", ["email", "public_profile"], {redirect_uri: "http://localhost/callback"}).then(function(result){
displayData($http, result.access_token);
}, function(error){
alert("Error: " + error);
});
}


function displayData($http, access_token)
{
$http.get("https://graph.facebook.com/v2.2/me", {params: {access_token: access_token, fields: "name,gender,location,picture", format: "json" }}).then(function(result) {
var name = result.data.name;
var gender = result.data.gender;
var picture = result.data.picture;


}, function(error) {
alert("Error: " + error);
});
}

关于android - 如何在 ionic 框架中获取用户数据(公共(public)资料和电子邮件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39574106/

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