Member Avatar for LastMitch

REALLY happy to see people playing with the API though. I've spent a lot of time on it this past week!!

I like it alot. But is it perfect yet?

Not yet at all. Still making lots of changes!! But I'm learning from the feedback and ideas everyone is coming up with.

Plus, nothing is ever going to be perfect. Nothing about DaniWeb is perfect. It can always be improved.

I know this has affected what some of you have written so far, and I reallllly apologize.

However, I've made a change to fetching multiple IDs at once. You now use a semicolon-delimited list as follows:

www.daniweb.com/api/members/1;67225
www.daniweb.com/api/forums/8;17;117

Member Avatar for LastMitch

Not yet at all. Still making lots of changes!! But I'm learning from the feedback and ideas everyone is coming up with.

This is alot work! But you're having fun! This is something different. I think people might enjoy this. Once this is all set and done. The instructions plus demo will help alot, it help me so I think it will help others. I can't wait til the final product.

Why a semicolon? I got no idea what you are doing.That is something I don't see often. It stands out. If you want it that way.

Member Avatar for diafol

What you can do for members instead is fetch their latest X posts and display the threads they are from

Yes, I could do that. I just searched for their 'id' within the 'posters' array.

www.daniweb.com/api/forums/8;17;117

Looks interesting.

http://www.daniweb.com/api/forums/2;1;61/articles

Seems to work too.

I know this has affected what some of you have written so far, and I reallllly apologize.

SHould only be a line or two of code. Yep, my card game - just had to tweak the base url and the implode - so no hassle at all. :)

Q: I've very limited experience of Auth, so is it safe to place Auth into the page and then add the $access_token to the querystring for retrieving general posts?

When I include the:

    $client_id = xxxx; 
    $client_secret = 'xxx'; 
    $current_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; 

    if ($access_token = $_REQUEST['access_token'])  
    {  
        // Pass your Access Token into all POST requests to authenticate yourself  
        echo 'Your Access Token for this session is ' . $access_token;

         //echo $access_token;
    } 
    else 
    { 

Even after clicking the 'Continue button' I get:

Notice: Undefined index: access_token in {my page} on line 6
Your Access Token for this session is xxxx

So the access token is retrieved, but the test throws an error.

WHen I refresh the url (with the access code in it):

{my page}?code=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

And try:

echo 'Your Access Token for this session is ' . $access_token;

print_r(json_decode(file_get_contents("http://www.daniweb.com/api/forums/17/articles?access_token = $access_token"),true));

I get

[error] => Cachebuster detected: Please pass in an access token to retrieve non-cached results. 

??EDIT

Doh!

articles?access_token = $access_token

Had spaces around the ' = ' !
Noob mistake.

http://www.daniweb.com/api/forums/2;1;61/articles
Seems to work too.

No, it doesn't. You're just fetching articles that are within the Software Development category. the 1 and 61 got stripped out.

And yes, a URL cannot contain spaces. :) Really glad to see you got it working!!

Really want to encourage people trying out our OAuth implementation.

Also, the demo code provided is a hand-coded OAuth 2.0 implementation, but there are lots of existing libraries out there that do it all for you and should work.

OK I made the URL above return a 404 error so that it's not confusing that it doesn't work.

Notice: Undefined index: access_token in {my page} on line 6

It's because my demo code isn't using PHP strict. I should fix that.

You should change line 5 to:

if (isset($_REQUEST['access_token']) AND $access_token = $_REQUEST['access_token'])

No, it doesn't. You're just fetching articles that are within the Software Development category. the 1 and 61 got stripped out.

Even though it wasn't a feature, you've inspired me, and now it is one. :)

Member Avatar for diafol

Great - it's really becoming feature rich :)

If I could just get the OAuth to work...

I think I'm missing the point here. For example, say I want to host an app (like the Box example I posted earlier) of a webpage, in order to use OAuth, I need to supply my membership number and secret key, right? But I shouldn't allow others to use the page then or what?

How would others use the page? They'd have to supply their own details? I'm mightily confused - as I say, I've very limited experience of OAuth.

Basically what you do is you supply your membership number and secret key into the PHP code. When you pass in your membership #, this is not used for the credentials of the end-user who uses the app. It's simply used so that I know who the author of the app is, so if you do any funny business like create an app that downvotes a million members, I know who to ban.

What will happen is when an end-user visits your webpage, they'll be quickly redirected to a form asking if they authorize diafol to have access to their account. If they click accept, then they'll be redirected back to your webpage, and you'll gain access to a token which can be used to access their account.

Diafol, are you still having trouble? I thought you were able to get it done when you realized you had the spaces around the equals sign?

If you were able to get the live demo example to work, then the $output array (where it prints $output['username'] to say hi to you) will be an array of your information when you access the page, an array of my information when I access the page, etc.

Member Avatar for diafol

Hi Dani, thanks for that. I'm afraid I haven't been able to work on it as I'm back to work tomorrow with about 60 books to mark! Never leave things to the last minute!

What will happen is when an end-user visits your webpage, they'll be quickly redirected to a form asking if they authorize diafol to have access to their account. If they click accept, then they'll be redirected back to your webpage, and you'll gain access to a token which can be used to access their account.

Okayy, I think I got that. So an user needs to be logged into DW in order for them to use the app. Right, I'll have a look soon (probably in a few days judging by the height of unmarked books still facing me).

Good luck marking!

So an user needs to be logged into DW in order for them to use the app.

When a user first accesses your app, they'll be temporarily redirected to our OAuth page, in which one of three things will happen:

  • If they're already logged into DaniWeb, they'll be asked to authorize that your app can access their account, and then they'll immediately be redirected back to your app.
  • If they're already logged into DaniWeb, and they've previously authorized your app, then the entire process is transparent to them, and they'll immediately be directed back to your app without realizing they ever left.
  • If they're not logged into DaniWeb, they'll be asked to join or login, and once they do, then they'll immediately be redirected back to your app.
Member Avatar for diafol

Got it! Thanks again.

I think your issue might have been related to a bug I recently introduced and subsequently recently fixed.

There's now full JSONP support which means you can authenticate entirely client-side with Javascript/jQuery. Check out the new Javascript demo example. :)

Member Avatar for LastMitch

There's now full JSONP support which means you can authenticate entirely client-side with Javascript/jQuery. Check out the new Javascript demo example. :)

It's looks nice and much better than regular one because of the animate button and new window.

I'm bit overwhelmed with that much updates.

I guess now everyone in order to used JQuery they much have this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

?

Yes, jQuery is required.

However, they each serve different purposes. One is serverside and the other is clientside. It depends what your application does to determine which one you will need.

Dani, maybe you should add the API announcement/link to API in your sig because it seems that the link posted on the very first page is broken?

I changed the link on the first page, but I'll also go ahead and add it to my sig.

riahc, I can't run your program because it says I don't have the latest version of .NET. Plus, I'm on a mac.

Yes, its a C# program. You will have to install Mono and Im not sure if its supported. I complied this in VS2012 so you need the 4.5 framework.

The screenshots is pretty much all there is to it. Nothing else.

Its only purpose is to show the compatibilty between C# and your API.

Once I understand OAuth, Im problably going to work on a posting app.

BTW, if someone wants the source code, Ill put it up as well with some comments :) although its very sloppy

@Riahc3, I'll take you up on that offer ;)

@Riahc3, I'll take you up on that offer ;)

OK, ill tidy it up a bit and put some slight comments.

Remember this is a proof of concept; The code is very dirty and "as is".

Not a worry in the slightest about the code's state, just interested in the actual code used :)

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.