Tag: swift

从App中的SSO获取access_token时对OAuth2请求的invalid_grant

我有一个与Uber API集成的iOS应用程序,我使用SSO来validation用户,然后在我的设备上本地保存accessToken&refreshToken。 然后,我打电话给我的服务器,使用javascript后台函数调用节点 – 超级( https://www.npmjs.com/package/node-uber )库来向Uber请求。 到目前为止,我试图用SSOlogin中的2个本地令牌来设置超级客户端,如下所示: var uber = new uberClient({ client_id: '…', client_secret: '…', server_token: '…', name: 'My App', sandbox: true, //optional access_token: accessToken, refresh_token: refreshToken }); 之后我想调用这个uber.requests.getEstimatesAsync端点: uber.requests.getEstimatesAsync({ "start_latitude": pickupLocation["lat"], "start_longitude": pickupLocation["lng"], "end_latitude": dropoffLocation["lat"], "end_longitude": dropoffLocation["lng"] }) .then(function(res) { console.log(JSON.stringify(res)); }) .error(function(err) { console.error(err); }); }) 虽然每次我得到一个“invalid_grant”错误400,而这样做。 我是否犯了一个错误的身份validation错误或设立Uber客户端错误? 是否有可能使用我的SSO accessToken&refreshToken然后在uber客户端,进行OAuth2authentication? 我认为访问和刷新令牌应该和Uber发回给SSO和OAuth2的一样。 […]

Swift – Spritekit:当节点触及底部边缘时,添加一个计数器(高分计算器)

我有我的代码设置,以便当我的球节点触摸屏幕的底部边缘程序检测到它。 我想要的是,每当它触及底部边缘,本质上是一个高分variables,一个variables增加1。 我到目前为止,但它只打印“你的分数是1”。 每次节点都触及底部边界。 任何帮助,将不胜感激。 干杯! 我的代码: func didBeginContact(contact: SKPhysicsContact) { // 1. Create local variables for two physics bodies var firstBody: SKPhysicsBody var secondBody: SKPhysicsBody var counter = Int() // 2. Assign the two physics bodies so that the one with the lower category is always stored in firstBody if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask { […]

无法通过socket.io将我的swift应用程序连接到node.js

我需要通过socket.io将我的iOS应用程序( swift )连接到node.js服务器。 我跟着socket.io官方教程 ,但我仍然坚持。 我试图连接到服务器,只是发出“authentication”,但我没有收到任何反馈后发出。 我的swift代码 class Socket{ var socket = SocketIOClient(socketURL: "localhost:8000", options:[.Log(true), .ForcePolling(true)]) init(){ self.addHandles() self.socket.connect() socket.connect() self.socket.emit("authentification","gaamy#test") } func addHandles(){ self.socket.on("connect") {data, ack in print("socket connected") print(data) } self.socket.on("error") {data in print("socket ERROR") print(data) } self.socket.on("reponse connection") {data in print("reponse connection") print(data) } self.socket.onAny { print("Got event: \($0.event), with items: \($0.items!)") […]

使用Angular2 Typescript和ServerJS访问.ENV属性

我一直在通过Angular2快速入门和教程,现在我试图设置从一个活的REST Api拉数据。 我需要通过Api调用authentication参数,我正在阅读的一切,我应该把这些参数到ENVvariables。 我无法弄清楚我应该怎么做。 我已经在我的本地服务器上创build了一个.env文件,我已经使用NPM将dotenv安装到我的项目中,但是我找不到关于如何使用dotenv的示例,似乎与我使用的TypeScript导入语法至。 这是我的main.ts: import { } from 'dotenv/config'; import { bootstrap } from '@angular/platform-browser-dynamic'; import { AppComponent } from './app.component'; bootstrap(AppComponent); 和一个示例app.component.ts: import { Component } from '@angular/core'; @Component({ selector: 'my-app', template: ` <h1>Up and running!</h1> <p>Do not show this at home: {{process.env.TWITTER_CONSUMER_KEY}}</p> `, styleUrls: ['style.css'] }) export class AppComponent { } […]

无法连接到服务器 – 迁移分析服务器iOS

我正在学习以下教程: https ://www.raywenderlich.com/128313/parse-server-tutorial,我已经成功完成了将数据迁移到mLab以及设置分析服务器的步骤。 我运行这个curl命令 $ curl -X GET \ -H "X-Parse-Application-Id: <myAppId>" \ -H "Content-Type: application/json" \ -d '{}' \ http://localhost:1337/parse/classes/_User 它返回我的所有用户的JSON。 这一步之后,教程说运行应用程序并发布一些数据。 但是,这是我卡住,我试图login时,得到以下错误代码, [Error]: Could not connect to the server. (Code: 100, Version: 1.12.0) [Error]: Could not connect to the server. (Code: 100, Version: 1.12.0) 。 我按照教程中的指示configuration了我的应用程序密钥和服务器url。 let configuration = ParseClientConfiguration { $0.applicationId = […]

如何在swift中显示API的图像?

我希望能够在swift中显示由我的nodeJS API( http://my_api/getUserImg )发送的图像。 这个具体的路线是像这样返回一个图像: fs.readFile(my_file.jpg', function(err,data) { if (err) res.json({success: false, message: err}); res.send(data);` } 谢谢,

Swift POST请求以错误的格式将body发送到node.js / express应用程序

我想从一个iOS应用程序使用Swift发送JSON对象。 一切正常,但是node.js / express后端的请求体中的主体处于aca-awkward格式,其中在Swift中分析的整个JSON对象是实际的关键字。 那么服务器上收到的是: req.body = { '{"email":"email","password":"password"}': '' } 我希望它是: { "email":"email","password":"password" } 所以我可以通过req.body.email访问键值 我是新来的ios和nodejs之间的http通信,所以也许这是正常的,但它非常恼人。 我的IOS邮政编码是: let url = NSURL(string: "http://localhost:3000/users") let request = NSMutableURLRequest(URL:url!) request.HTTPMethod = "POST" var login_details: [String: AnyObject] = [ "email" : "\(self.email_field.text)", "password" : "\(self.password_field.text)" ] let valid = NSJSONSerialization.isValidJSONObject(login_details) var err: NSError? request.HTTPBody = NSJSONSerialization.dataWithJSONObject(login_details, options: nil, […]

如何在swift中执行terminal命令?

我是新来的。 我如何从Swift代码运行这个过程? 打开terminal窗口 执行cd Desktop/firebase-mac 执行npm start 我真正想要做的是从Swift代码单击启动节点服务器。

JSON序列化使用networking

我有问题的方式,我收到服务器的JSON。 有学生数组(字典)包装在字典中: var students:[[String: String]] = [] students.append(["id":"2", "name":"joe"]); students.append(["id":"3", "name":"jake"]); students.append(["id":"4", "name":"may"]); students.append(["id":"1", "name":"donna"]); let json:[String:[[String:String]]] = ["students" : students] 当使用NSJSONSerialization打印JSON var data = NSJSONSerialization.dataWithJSONObject(json, options: NSJSONWritingOptions.PrettyPrinted, error: &error) println(NSString(data: data!, encoding: NSUTF8StringEncoding)) { "students" : [ { "id" : "2", "name" : "joe" }, { "id" : "3", "name" : "jake" }, { […]

我如何插入一个datetypes到iOS Swift的MongoDB(通过JSON和Node.js)

有没有人设法用iOS Swift(或Objective C)在MongoDB中插入datetypes? 我知道我可以像这样存储一个string: let now = NSDate() let nowISO8601 = ISO8601Format.stringFromDate(now) 但是真的,我想要构造一个有效的JSON对象,并在插入到MongoDB中时生成一个datetypes。 下面是我的Swift代码的简化版本,通过Node.js Web服务发布到MongoDB: let dateData = ["some_date" : nowISO8601] if NSJSONSerialization.isValidJSONObject(dateData){ let url = NSURL(string: "http://mynodejsurl") var request = NSMutableURLRequest(URL: url!) var data = NSJSONSerialization.dataWithJSONObject(dateData, options: nil, error: nil) request.addValue("application/json", forHTTPHeaderField: "Content-Type") request.HTTPMethod = "POST" request.HTTPBody = data let task = session.dataTaskWithRequest(request, completionHandler: […]