Member Avatar for diafol

Hi all, following a chat with Dani, I'm just posting an example of a jQuery OAuth implementation. Major updates to come over the next weeks and months, but it's a start. I'll be publishing the code once I've cleaned it up and de-noobified it somewhat. :)

http://dw.diafol.org/

Recommended Answers

All 28 Replies

I get a 500 server error :(

Member Avatar for diafol

Fixed!

Yep, I was having issues with GETTEXT, so had to swap a few include files around - but I got them in the wrong order!

I love the Twitter Boostrap look!! Spiffy!!

Two things ...

  1. You probably want to pass ?include_self=1 when you fetch /forums/descendants to include the top level categories as well, and not JUST their descendants.
  2. I'm not sure if it's related to that or not, but my list has an article that says f: undefined. It points to this thread: http://www.daniweb.com/hardware-and-software/microsoft-windows/viruses-spyware-and-other-nasties/threads/448757/cannot-download-attachments-in-gmail
Member Avatar for diafol

Thanks for the heads up. I didn't know about the include_self! OK, I just hope I get the same json format :)

OK, I just hope I get the same json format :)

You will! However, it seems like it isn't able to determine the forum name when you're in a sub-forum, like one of the sub-forums within Microsoft Windows. Are you sure you're pulling descendants and not just children?

Member Avatar for diafol

Ok, I've added the parameter - does it work for you now?

No :(

Member Avatar for diafol

OK, I'll hard code your fave forums into my code and see if I can replicate the problem.
Hmm, it's stopped working - can't splice the json - did you change anything?

Ah - I now see the "0": etc 'keys'

I didn't change anything????

Oh shoot, you're right! I did break something!! Fixing ......

Fixed. Sorry about that.

Don't ya just love working with a moving target API? :)

GRR, not fixed ... hold on :)

NOW fixed.

Member Avatar for diafol

OK, you've officially given me a freaking headache. :)
He he.

I was trying to add pagination and I accidentally put the pagination object inside the data object ... All good now.

Member Avatar for diafol

OK, I think I tracked down the problem. If you have a top-level forum as your favourite, then children don't get taken into account in my code, so although the posts will be extracted, the program can't identify the forum as it has no id-title array item. OK, that went totally over my head until now. I've been beating my head against a wall as to why Forum 10 kept showing an undefined title. :)

//OK I think I've sorted it now - that was horrible :( Managed to sort it without a recursive function - but will probably need to do that to tidy up the code.

I extracted json from the nested forums (without descendants and include_self) as that allowed me to search children easily (nested loops).

Diafol,

I might be confused, but I don't think that you should need to do any type of nested loops.

Just look at the list of my favorite forums when you pull /me

Then, do:

http://www.daniweb.com/api/forums/1;2;3;4;5/descendants?include_self=1

This will give you a flat list of all of my favorite forums and all their descendants.

Member Avatar for diafol

aw. i think you're right. my comparison top get the titles used the original favourite forums - that's why I wasn't getting the child forums. DOH! and DOUBLE DOH! Thanks.

Favorite forums have always been the same. It's just an array of forum IDs within /me. Just take that array of forum IDs and collapse it into a semi-colon delimited list, and fetch all those forums and all their descendants at once.

Member Avatar for diafol

That's what I did:

ff, myForums are global vars (array)

    $.getJSON('http://www.daniweb.com/api/me?access_token=' + access_token + '&callback=?').done(function(json){
        me = json.data.id;
        $.each(json.data.favorite_forums, function(i,v){
            ff.push(v.forum.id);
        });
        forums = ff.join(';');
        $.getJSON('http://www.daniweb.com/api/forums/'+ forums + '/descendants?include_self=1&access_token=' + access_token + '&callback=?').done(function(json){

            $.each(json.data,function(i,v){
                myForums['f' + v.id] = v.title;
            });
            getArticles();
        });
    });

Hopefully, it's fixed :)

OK yeah, that should work :) Much more elegant than going through nested loops.

Just tested it and i'm seeing Windows Vista nd Win 7/8 and Windows 2000/XP ... seems to all be working now :)

Member Avatar for diafol

Yipee! OK, I think I'm gonna leave it there on that particular app.

BTW - if I want to place more that one app on one site, should I create a new application for each or should I just use the one and reuse the same client id etc?

BTW - if I want to place more that one app on one site, should I create a new application for each or should I just use the one and reuse the same client id etc?

It's up to you with two caveats:

  1. If you use clientside OAuth 2.0, the domain registered must match the domain the app resides on.
  2. The application name and website is displayed when asking for authorization from end-users, so you'll want it to be a friendly name. Whether you create a single app or multiple apps from the same domain name would depend purely on end-user usability. There's no advantage or disadvantage.
Member Avatar for diafol
  1. Yep
  2. I didn't think of the name presented to the public :) Good job I didn't name it something profane!

Thanks.

I like that you included documentation now! :)

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.