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
Related
I used the below link.
https://api.roblox.com/users/**$UserID**/onlinestatus
for example:
https://api.roblox.com/users/543226965/onlinestatus
I have been receiving an error message from last time. The error message is given below.
{"errors":[{"code":404,"message":"NotFound"}]}
I heard the roblox API have been changed, but I can not find the right solutions, so I will be grateful for any answer.
Thanks.
It appears that you're trying to access the user's online status. As of right now, you can access this information by querying https://api.roblox.com/users/<user_id>, which returns a JSON object. Looking up IsOnline in the dictionary should return what you're trying to get
Here's an example I coded in Python:
import requests
res = requests.get(url='https://api.roblox.com/users/543226965')
res = res.json()
print(res['IsOnline'])
>>> True/False
I'm currently trying to integrate my website's API with my discord BOT and got stuck on a small issue I can't find solution for.
Basically, my API returns some social media connections like steam or twitch. All working fine until the user doesn't connect their socials, so the API provides "null" cause there's no connection.
I've tried to do "If twitch is null then don't addFiled", but bot either doesn't care or throws "cannot read content of "null" when I tried twitch.content == 'null'.
let twitchName = body.data.socials.twitch
if (twitchName == 'null') {
return
} else {
driverembed.addField('Twitch.tv', `[${body.data.socials.twitch}](https://www.twitch.tv/${body.data.socials.twitch})`)
}
So, even if the twitch comes back as "null", the bot adds the field to the embed.
I'd greatly appriciate any help possible! Thank you.
if (twitchName == 'null') - you are not checking if twitch is null, you are checking if its a string with value "null".
if (twitchName == null) or even if (!twitchName) should work.
I'm trying to write a react native app which will stream some tracks from Soundcloud. As a test, I've been playing with the API using python, and I'm able to make requests to resolve the url, pull the playlists/tracks, and everything else I need.
With that said, when making a request to the stream_url of any given track, I get a 401 error.
The current url in question is:
https://api.soundcloud.com/tracks/699691660/stream?client_id=PGBAyVqBYXvDBjeaz3kSsHAMnr1fndq1
I've tried it without the ?client_id..., I have tried replacing the ? with &, I've tried getting another client_id, I've tried it with allow_redirects as both true and false, but nothing seems to work. Any help would be greatly appreciated.
The streamable property of every track is True, so it shouldn't be a permissions issue.
Edit:
After doing a bit of research, I've found a semi-successful workaround. The /stream endpoint of the API is still not working, but if you change your destination endpoint to http://feeds.soundcloud.com/users/soundcloud:users:/sounds.rss, it'll give you an RSS feed that's (mostly) the same as what you'd get by using the tracks or playlists API endpoint.
The link contained therein can be streamed.
Okay, I think I have found a generalized solution that will work for most people. I wish it were easier, but it's the simplest thing I've found yet.
Use API to pull tracks from user. You can use linked_partitioning and the next_href property to gather everything because there's a maximum limit of 200 tracks per call.
Using the data pulled down in the JSON, you can use the permalink_url key to get the same thing you would type into the browser.
Make a request to the permalink_url and access the HTML. You'll need to do some parsing, but the url you'll want will be something to the effect of:
"https://api-v2.soundcloud.com/media/soundcloud:tracks:488625309/c0d9b93d-4a34-4ccf-8e16-7a87cfaa9f79/stream/progressive"
You could probably use a regex to parse this out simply.
Make a request to this url adding ?client_id=... and it'll give you YET ANOTHER url in its return json.
Using the url returned from the previous step, you can link directly to that in the browser, and it'll take you to your track content. I checked on VLC by inputting the link and it streams correctly.
Hopefully this helps some of you out with your developing.
Since I have the same problem, the answer from #Default motivated me to look for a solution. But I did not understand the workaround with the permalink_url in the steps 2 and 3. The easier solution could be:
Fetch for example user track likes using api-v2 endpoint like this:
https://api-v2.soundcloud.com/users/<user_id>/track_likes?client_id=<client_id>
In the response we can finde the needed URL like mentioned from #Default in his answer:
collection: [
{
track: {
media: {
transcodings:[
...
{
url: "https://api-v2.soundcloud.com/media/soundcloud:tracks:713339251/0ab1d60e-e417-4918-b10f-81d572b862dd/stream/progressive"
...
}
]
}
}
...
]
Make request to this URL with client_id as a query param and you get another URL with that you can stream/download the track
Note that the api-v2 is still not public and the request from your client probably will be blocked by CORS.
As mentioned by #user208685 the solution can be a bit simpler by using the SoundCloud API v2:
Obtain the track ID (e.g. using the public API at https://developers.soundcloud.com/docs)
Get JSON from https://api-v2.soundcloud.com/tracks/TRACK_ID?client_id=CLIENT_ID
From JSON parse MP3 progressive stream URL
From stream URL get MP3 file URL
Play media from MP3 file URL
Note: This link is only valid for a limited amount of time and can be regenerated by repeating steps 3. to 5.
Example in node (with node-fetch):
const clientId = 'YOUR_CLIENT_ID';
(async () => {
let response = await fetch(`https://api.soundcloud.com/resolve?url=https://soundcloud.com/d-o-lestrade/gabriel-ananda-maceo-plex-solitary-daze-original-mix&client_id=${clientId}`);
const track = await response.json();
const trackId = track.id;
response = await fetch(`https://api-v2.soundcloud.com/tracks/${trackId}?client_id=${clientId}`);
const trackV2 = await response.json();
const streamUrl = trackV2.media.transcodings.filter(
transcoding => transcoding.format.protocol === 'progressive'
)[0].url;
response = await fetch(`${streamUrl}?client_id=${clientId}`);
const stream = await response.json();
const mp3Url = stream.url;
console.log(mp3Url);
})();
For a similar solution in Python, check this GitHub issue: https://github.com/soundcloud/soundcloud-python/issues/87
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!
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);
?>