Member Avatar for diafol

No worries - I was just playing. I'll have a little tinker later on. :)

Member Avatar for diafol

Hmmm. Some of the examples don't seem to work for me:

// Initialize cURL to send a GET request and return the response as a string 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

// Fetch everything about Dani from her profile 
curl_setopt($ch, CURLOPT_URL, 
    urlencode('http://www.daniweb.com/api/entity/Username/diafol')); 

// Receive and subsequently decode the response from JSON into a PHP array 
$output = json_decode(curl_exec($ch), true); 

// Close the cURL request 
curl_close($ch); 

// Print out the resulting PHP multi-dimensional associative array 
var_dump($output); 
?>



<?php 
//$myNum set 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

// Fetch the second page of upvoted posts by Dani 
curl_setopt($ch, CURLOPT_URL, 
    urlencode("http://www.daniweb.com/api/posts/Member/$myNum/upvoted/2")); 

$output = json_decode(curl_exec($ch), true); 
curl_close($ch); 
var_dump($output); 
?>

I just get NULL. THe rss code works though.

What is $myNum??

Member Avatar for diafol

I used '1' (as in the doc), so I assumed this referred to the member number. I tried a few different ones, to no avail.

$myNum = 1 etc

so I didn't have to wade through and hard code every time.

Is the API (the snippets I included) working for you? None of the json/gets seem to work for me. :(

SOrry about that. It was a typo in my examples that I was wrapping the URL being passed into cURL with urlencode().

I can certainly see the benefit of software that lets you post on your own terms (if you don't like the DaniWeb editor, for example)

You caught me quick :P

But yes, I understand the security issues a writing ability would cause...

Yes, I said it ... we'll have write functionality.

YES! :D

Expect a desktop client from me soon :P

Fixed!! :) The code you posted should work now.

Full OAuth for the win :) Now you can write 'Login with DaniWeb' applications the same way there's Log In with Facebook.

Let's see how many developers out there want to leverage our one million members!

For the C# users in this thread, all you need to do is use RestSharp. It will handle the API rather nicely. Here is some sample code to use the WhoAmI method:

var accessToken = "use the documentation to learn how to get this";
var client = new RestClient("http://www.daniweb.com/api");
var request = new RestRequest("me", Method.POST);
request.AddParameter("access_token", accessToken);
var response = client.Execute(request);
Member Avatar for diafol

Would it be possible to include sections on different languages pHp, c# etc in the documentation as they become available? May save people from having to reinvent the wheel?

I was just about to start a new thread asking if people could post ports of my demo in different languages in our code snippet library, and I'll link to them all from within the documentation.

So I have an idea for an app: What about writing a little page where it shows you the top members you recently had communication with?

The API doesn't seem to allow in giving a vote with comment.

When you vote with a comment, lots of things happen: You affect someone's reputation, you send an email to the poster, etc.

In the interests of having all write queries be as innocuous as possible right now, I've opted to not provide an easy way for someone to write a bot capable of trolling and emailing a million members.

The idea is the API currently has fully functional read capability, plus the ability to quickly vote on or watch posts you might stumble across, which is an ideal feature set IMHO for a mobile application (hint hint).

At one point in time (did you perhaps Donate to the site?) you had the ability to set a custom user title, and you chose Postaholic.

However, your member profile currently doesn't have the privilege of custom user titles, and therefore the site is displaying the generic one.

Should your member permissions ever change, the custom user title is waiting for you in the database.

Disclaimer: We no longer offer custom user titles to sponsors. Now you must be a moderator or someone special.

I can't remember that I've ever had the ability to change it. And if I've had the ability at some point in time, I can assure you that I never made a change to my user title.

That's very odd, I'm not sure where Postaholic came from.

Oh, you know what I think happened. I think when we switched platforms, the current user titles were migrated over to the database regardless of whether they were custom or not.

Member Avatar for diafol

Q: In my fiddling with things, is there a way of retrieving multiple users' data as json in one call? It's reaaally slow with say 8 calls in succession.

commented: Good question. +0

I'm not home now, but when I get home (or tomorrow) I'll look into this.

Lots of work happening right now on speed as well.

Also, I'm going to be changing the design of the API docs shortly. Everything will stay the same, just the documentation is being reorganized.

I like the idea of the API, and the page for it... all i know to do is use it at one point! Nice job dani!

Thanks! I'm spending a lot of time on it, trying to make (at least the read functionality) as robust and concise as possible.

For the C# users in this thread, all you need to do is use RestSharp. It will handle the API rather nicely. Here is some sample code to use the WhoAmI method:

var accessToken = "use the documentation to learn how to get this";

Mind setting a example on how to aquire the accesstoken in C#?

Member Avatar for diafol

BTW - the file_get_contents() works for me, but I know certain hosts don't allow this, so cURL may be the only option for them. Does the documentation need to reflect this, or do you think that's up to the user to figure out?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.