0

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/

2
Contributors
28
Replies
97
Views
4 Years
Discussion Span
Last Post by Dani
Featured Replies
  • 1
    Dani 1,638   4 Years Ago

    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 … Read More

  • 1
    Dani 1,638   4 Years Ago

    I like that you included documentation now! :) Read More

0

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!

0

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

0

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?

0

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'

Edited by diafol

0

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

0

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).

Edited by diafol

0

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.

0

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.

0

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 :)

Edited by diafol

0

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

0

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?

0

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.
0
  1. Yep
  2. I didn't think of the name presented to the public :) Good job I didn't name it something profane!

Thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.