Saving information from ios app to web server (POST JSON) - objective-c

The problem i am having is that i am unable to so save information from my ios application to my web server, I am currently app to retrieve the data using JSON and parsing that data.
I have written the php code for the request and it is stored on my server:
...else
{
// updating record
$q = sprintf("update phone_book set name = '%s', phoneNumber = '%s', email = '%s', phoneNumber = '%s' where name = '%s'",
mysql_real_escape_string($_GET["name"]),
mysql_real_escape_string($_GET["phoneNumber"]),
mysql_real_escape_string($_GET["email"]),
mysql_real_escape_string($_GET["address"]));
}
However I have looked everywhere and am unable to find information on how i could use post this information from my application to the web server.
Would appreciate any help. Thanks!

Use this api for post and get calls and object mapping
https://github.com/RestKit/RestKit

This actually wasent to hard. Another option instead of using REST was to POST JSON from the iOS application sending the JSON to a site where a php file contains the code. The fixed code inside the PHP would look like:
...
$json_post = json_decode(file_get_contents ('php://input'),1);
$name = $json_post['name'];
$phone = $json_post['phone'];
$aQuery = "UPDATE phone_book SET phoneNumber = '$phone' WHERE name = '$name' ";
mysql_query($aQuery);
...
If anyone requires anymore help feel free to leave a comment. Good Luck!

Related

Steam API: How to query a server to get server info (not using A2S)?

I would like to know how to use the Steamworks Web API to query a server to get information (server name, game, map, players, etc.). I know that using the A2S query (https://developer.valvesoftware.com/wiki/Server_queries) can give that information, but I would like to know if it is possible using the Steamworks Web API instead.
Thanks!
With IGameServersService/GetServerList. Here is an example:
https://api.steampowered.com/IGameServersService/GetServerList/v1/?key=API_KEY&filter=addr\YOUR.IP.ADRESS:PORT
For example, to get the map of a Garry's Mod server, you can try the following (code example is in PHP):
$url = "https://api.steampowered.com/IGameServersService/GetServerList/v1/?key=API_KEY&filter=addr\185.254.99.6:27015";
$json = file_get_contents($url);
$table2 = json_decode($json, true);
$table = $table2["response"]["servers"][0];
$mapname = $table['map'];

Karate: Trying to get global headers working [duplicate]

This question already has an answer here:
Is there a way to update the headers in one feature file and use the Auth token from Karate.config.js?
(1 answer)
Closed 1 year ago.
I'm trying to setup a framework to run Graphql calls and create and E2E environment.
I've got the following setup so far but i can't seem to get the headers part of it working. i have managed to set the auth for each request and it all works but as it logs in for each request it doesn't really work as expected.
I want do the following steps:
run a login Test (different usernames valid/invalid)
run a logout test (Ensure token is removed)
Then login with correct user and extract the "set-cookie" header (to use globally for all future requests)
I was trying to use the following:
Karate-config.js
karate.callSingle('classpath:com/Auth/common-headers.feature', config);
headers.js
function fn() {
var headers = {}
headers["set-cookie"] = sessionAccessId
karate.log('Cookie Value: ', headers)
return headers
}
common-headers.feature
Feature: Login to Application and extract header
Background:
* url serverAuthenticateUri
* header Accept = 'application/json'
Scenario: 'Login to the system given credentials'
Given request { username: '#(username)', password: '#(password)'}
When method post
Then status 200
And match $.success == '#(result)'
And def myResult = response
* def sessionAccessId = responseHeaders['set-cookie'][0]
* configure headers = read('classpath:headers.js')
* print 'headers:', karate.prevRequest.headers
feature-file.feature
Feature: sample test script
Background:
* url serverBaseUri
* def caseResp = call read('classpath:com/E2E/POC/CommonFeatures/CreateCaseRequest.feature')
* def caseReqId = caseResp.response.data.createCaseAndRequest.siblings[0].id
* def caseId = caseResp.response.data.createCaseAndRequest.siblings[0].forensicCaseId
* def graphQlCallsPath = 'classpath:com/E2E/POC/GraphQl/intForensic/'
* def commmonFiles = 'classpath:E2E/CommonFiles/'
Scenario: TC1a - Request Server Details from Config DB (1st Run):
Should handle requesting Server Details Data from Config Database.
* def queryFile = graphQlCallsPath + '20-TC1a_req_req_valid_id.graphql'
* def responseFile = graphQlCallsPath + '20-TC1a_resp_req_valid_id.json'
Given def query = read(queryFile)
And replace query.reqId = caseReqId
And request { query: '#(query)' }
When method post
Then status 200
And json resp = read(responseFile)
And replace resp.reqId = caseReqId
And replace resp.caseID = caseId
And match resp == $
I can log in correctly and i get the set-cookie token but this isn't being passed on the feature-file.feature and i get an error saying "not logged in" in the response.
Any help appreciated! I might be looking at this totally wrong and i have tried to follow the shared-scope as much as i can but can't understand in.
Please make this change and hopefully that works !
headers["set-cookie"] = karate.get('sessionAccessId');
Why is explained here: (read the whole section carefully) https://github.com/intuit/karate#configure-headers
EDIT: one more suggestion:
var temp = karate.callSingle('classpath:com/Auth/common-headers.feature', config);
karate.configure('headers', { 'set-cookie': temp.sessionAccessId });
Some extra suggestions:
If you have just started with Karate - based on your question I would suggest you get one flow working in a single Scenario first without any use of call and with nothing whatsoever in karate-config.js. Hard-code everything and get it working first. Use the header keyword to set any headers you need. I also see you are trying to set a set-cookie header (which may work) but Karate has a special keyword for cookie.
And don't even think about callSingle() to start with :)
Once you get that first "hard-coded" flow working, then attempt to configure headers and then only finally try to do "framework" stuff. You seem to have jumped straight into super-complexity without getting the basics right.
Please read this other answer as well, because I suspect that you or someone in your team is attempting to introduce what I refer to as "too much re-use": https://stackoverflow.com/a/54126724/143475 - try not to do this.
Also note that your question is so complex that I have not been able to follow it, so please ask a simpler or more specifc question next time. If you still are stuck, kindly follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Download / backup all soundcloud user data

I tried searching for a tool that would download all data related to a soundcloud user (uploaded tracks, likes/collection, reposts, playlists, comments, groups etc), backing it up locally, but haven't had luck so far. The user data format is not crucially important, and could be something like XML or JSON. I guess it wouldn't be hard to create it using their API, but I thought it's strange there's no tool like that already, so I wanted to ask here first.
Not a complete answer, but I'll just gather here a few bits of information that might be useful to somebody eventually. Based on this article https://helgesverre.com/blog/fetch-info-from-soundcloud-api/
First you need to register an app here, where you'll get your client id
http://soundcloud.com/you/apps/new
$clientid = "*******"; // Your API Client ID
$userid = "****"; // ID of the user you are fetching the information for
$username = "*****";
// build our API URL
$url = "http://api.soundcloud.com/resolve.json? url=http://soundcloud.com/{$username}&client_id={$clientid}";
$user_json = file_get_contents($url);
$tracks_url = "http://api.soundcloud.com/users/{$userid}/tracks.json?client_id={$clientid}";
$tracks_json = file_get_contents($tracks_url);
$playlists_url = "http://api.soundcloud.com/users/{$userid}/playlists.json?client_id={$clientid}";
$playlists_json = file_get_contents($playlists_url);
$followings_url = "http://api.soundcloud.com/users/{$userid}/followings.json?client_id={$clientid}&page_size=200"; // 200 is max
$followings_json = file_get_contents($followings_url);
$followers_url = "http://api.soundcloud.com/users/{$userid}/followers.json?client_id={$clientid}&page_size=200"; // 200 is max
$followers_json = file_get_contents($followers_url);
$reposts_url = "http://api-v2.soundcloud.com/profile/soundcloud:users:{$userid}?client_id={$clientid}&limit=1000&offset=0"; // 1000 works
$reposts_json = file_get_contents($reposts_url);

How to use JSON object as variable in objective c?

I'm developing an Server-Client application in Xcode 4.2
The application saves some user informations and sends them in a HTTP GET request to server via server url.
As response, I have text like this:
2011-12-30 15:44:02.120 smartHome[340:f803] {
button = 1;
key = 181abc88e57c37a42769;
message = (
{
ID = 1;
date = "2011-12-10 16:00:00";
message = asdf;
status = 1;
"user_id" = 2;
}
);
"wrong_user" = 0;
}
(2/Jan/2012)
Sorry for such confusing edits but i haven't overcome my deal yet. I need to parse this JSON text(i think it is called text:) and do some implemetations on the results.. I have to use, for example, the message object and its status value, if status equals to 1 i will trigger a Notification in my App. As like that, if the button comes me as a value with 1 i will send a POST to the server and request for the button id and title attributes..
There are a lot of tutorials about parsing but all i saw are about Twitter or flickr APIs, unfortunately i couldnt desing a clear way to solve my problem.. I tried ASIHTTPRequest but i faced some problems with setting up the Libraries. And if i'm not wrong, ASIHTTPRequest is not such a good idea in i-OS 5 (i m not sure about this).. Anyway, from this point can anyone please help me about how to parse the JSON above?
Finaly i figured out, i have done everything before, i just realized that..
for example when i tried:
NSString*key1=[ result objectForKey:#"key" ];
NSString *kAndVal=[result objectForKey:#"button"];
NSLog(#"\n%# : %#", key1, kAndVal);
i got the key and button values above.. I hope this answer will save lots of newbies like me out of trouble..
You should parse your JSON anwer using a JSON parser. iOS 5 has its own JSON parser. In case you want to support iOS 4 check out JSONKIT https://github.com/johnezang/JSONKit

AS3 Flash api not setting game category app score - acces token error

Hope it's not a very noobish question i'm asking :) -
I'm trying to set the score parameter for my app ( Game category app ) with the AS3 Flash API ( Which i see is a wrapper around JS Api ) but i keep getting the "(#15) This method must be called with an app access_token" error, i've also tried a test call with the Graph API Explorer and the result is the same.( with generated acces token of the app and copy/pasted acces token )
I've searched the permission tables and i've set both publish_actions and user_games_activity for the authentification process.
Getting works perfectly ( i can receive basic information without any problems also score information but it's just an empty array probably because it isn't set ) posting seems to be the culprit
I want to know if i'm doing something wrong ( something like there's an additional auth process necessary on my server side )
If you guys have any ideea please help this is becoming very frustrating
Thanks in advance :D
Finally found the solution.
Here is the correct AS3 code:
var data:Object = new Object();
data.score = 285;
data.access_token = APP_ACCESS_TOKEN;
var requestType:String = "POST";
Facebook.api( Facebook.getAuthResponse().uid + "/scores/" , handlePostScoreComplete, data, requestType);
You MUST get the app access token using PHP or some other client-side SDK, not the Javascript SDK because it needs the app secret.
So in PHP you must get the access token and then you can pass it to Flash:
<?php
$APPLICATION_ID = YOUR_APP_ID;
$APPLICATION_SECRET = YOUR_APP_SECRET;
$token_url = "https://graph.facebook.com/oauth/access_token?" .
"client_id=" . $APPLICATION_ID .
"&client_secret=" . $APPLICATION_SECRET .
"&grant_type=client_credentials";
$app_token = file_get_contents($token_url);
?>