0

Would it be useful to have an update thread for when you make changes to the API structure for example. Did forum_id get changed from forumid or then to just id for certain forums (can_read)? My app stopped working and I couldn't work out why - then iterating over the json, I noticed the change in name?

3
Contributors
43
Replies
240
Views
4 Years
Discussion Span
Last Post by Dani
Featured Replies
  • 2
    Dani 1,638   4 Years Ago

    Ah, I see what you mean. I think this might be a bug. I'll look into it right away. Read More

  • 1
    Dani 1,638   4 Years Ago

    > Dani, what's the cutoff date for RSS feeds? 90 days > is there also a maximum number of items returned 100 items > Additionally, in your RSS documentation 'threads' is missing from the article type list. Will look into it. > http://www.daniweb.com/api/forums/31/ancestors?access_token=MYACCESSTOKEN No valid data meets your criteria because … Read More

  • 1
    Dani 1,638   4 Years Ago

    I might just do that :) Read More

  • 1
    Dani 1,638   4 Years Ago

    > The first returns data for you and me. I'd expect the second to return 400 bad request since there is no page 2 (in line with other requests), but it appears to return random data (perhaps page 2 of all members). Right, that's exactly what's happening. It's a bug. … Read More

  • 1

    > I noticed that the upvote wasn't cancelled by a downvote on the same post. Is that reproducible? Yes, it is reproducible. Once voted, a second call (up or down) returns a JSON success false. So with the API you cannot revoke your choice at the moment. Read More

0

Changes to the API structure happened a bunch of days ago, when I said, "Making changes to the API strucutre" and you said, "OK, I'll wait!" and then I said, "OK Done!".

In all honesty, I think that I introduced a bug at the same time Friday afternoon as I introduced the DST timestamp bug where the same property was being shown in its original form and in its new friendly form. So, for example, both forumid AND forum_id were being printed. I fixed that yesterday at the same time as I fixed the DST bug.

Soooorrryyy!!

0

No prob.

I'm not going 'Grrrrr!' - honestly :)

To be fair, my apalling js/JQ skills are getting a proper workout, so it's all good.

0

Oh, I am going GRRR because I introduced these two bugs Friday, and, to be honest, while I'm very grateful that you figured out the timezone issue only a day later, it was a bitch and a half to fix because I had a day and a half of content in the database with the wrong timestamp.

0

Oh well, thankfully you were able to correct it before too much damage was done. :)

0

OK, new problem. The oAuth getting PM data (inbox/outbox) seems to be getting the best of me.

Could you confirm that it's working? All other oAuth calls work fine for me, except these - and yes I do have messages in both.

Thanks.

2

Ah, I see what you mean. I think this might be a bug. I'll look into it right away.

0

Thanks :)

Anybody have any ideas about...

The OAuth documentation code has me a bit stumped: e.g.

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

if (isset($_REQUEST['access_token']) AND $access_token = $_REQUEST['access_token']) 
{ 
    // Pass your Access Token into all POST requests to authenticate yourself 
    echo 'INSIDE CODE: Your Access Token for this session is ' . $access_token . "<br />";
}
else
{
    // Send your website visitor to our authorization page along with a way to get back
    if (!isset($_REQUEST['code']))
    {
        header("Location: http://www.daniweb.com/api/oauth?client_id=$client_id&redirect_uri=".urlencode($current_url));
    }

    // Upon authorizing your access, they will be redirected to your redirect_uri
    //  and Code will be passed along as a query string parameter

    // Initialize cURL to send a POST request
    $ch = curl_init('http://www.daniweb.com/api/access_token');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_POST, true);

    // Use the Code to acquire a temporary Access Token
    //  to use for the current session
    //  You can save the Code to retrieve a new Access Token
    //  when it expires (and invalidate the existing Access Token
    //  if it hasn't expired yet)
    curl_setopt($ch, CURLOPT_POSTFIELDS, array(
        'code' => $_REQUEST['code'],
        'redirect_uri' => $current_url,
        'client_id' => $client_id,
        'client_secret' => $client_secret
    ));
    curl_exec($ch);
    curl_close($ch);
}

echo 'POST CODE Access Token: ' . $access_token . "<br />";

I get this output:

INSIDE CODE: Your Access Token for this session is ab033f80463fdbab7ff4b72b8ae92f96
POST CODE Access Token: ab033f80463fdbab7ff4b72b8ae92f96

Notice: Undefined variable: access_token in C:\xampp\htdocs\xxxxxxxxxxx on line 90
POST CODE Access Token:

Line 90, being the last line in the code block above. Any idea why it's doing this?
I don't use cURL a lot, so it's got me a bit flummoxed.

0

Dani, what's the cutoff date for RSS feeds? I mean, if I get the RSS feed for the PHP tutorials I get an empty feed. Last tutorial was 4 months ago. You don't show anything older than a month, or is there also a maximum number of items returned?

Additionally, in your RSS documentation 'threads' is missing from the article type list.

One more concerning the following requests:

http://www.daniweb.com/api/forums/31/ancestors?access_token=MYACCESSTOKEN
returns false (bad request)

http://www.daniweb.com/api/forums/31/ancestors?include_self=true&access_token=MYACCESSTOKEN
return data for web dev

http://www.daniweb.com/api/forums/31/ancestors?include_self=false&access_token=MYACCESSTOKEN
returns data for web dev

I understand the second result, but not the difference between the first and the third (as include_self should be false by default according to your documentation). Same happens with or without a token.

Edited by pritaeas

1

Dani, what's the cutoff date for RSS feeds?

90 days

is there also a maximum number of items returned

100 items

Additionally, in your RSS documentation 'threads' is missing from the article type list.

Will look into it.

http://www.daniweb.com/api/forums/31/ancestors?access_token=MYACCESSTOKEN

No valid data meets your criteria because you are trying to fetch the forum's ancestors and a top-level category (Web Development) that has no ancestors, so there is nothing to return.

http://www.daniweb.com/api/forums/31/ancestors?include_self=true&access_token=MYACCESSTOKEN

Here, you're again trying to fetch Web Development's ancestors, but this time you're saying to include itself also. It has no ancestors still, but the least it can do here is return itself.

http://www.daniweb.com/api/forums/31/ancestors?include_self=false&access_token=MYACCESSTOKEN

When you pass false in as a query string parameter in this manner, it is being treated as a literal string "false" as opposed to the boolean value of false. Therefore, include_self evaluates to true because PHP defines any non-zero integer or string as true. You can do ?include_self=0 or you can pass false in through cURL as so:

$data = array(
    'include_self' => false,
    'access_token' => $mytoken
);
$request = curl_init('http://www.daniweb.com/api/forums/31/ancestors');
curl_setopt($request, CURLOPT_POSTFIELDS, $data);

Please note that passing in the query string parameter as you are doing is synonymous with doing this:

$data = array(
    'include_self' => "false",
    'access_token' => $mytoken
);

See the difference?

Votes + Comments
Thanks
0

It doesn't matter if you are using GET or POST. Pass 0/1 in as a query string parameter as part of the URL. Pass 0/1 or true/false in as an array parameter when using the curl_setopt() function. This is not a DaniWeb-specific rule. It's a PHP rule. :)

0

Pass 0/1 in as a query string parameter as part of the URL

Looking for this answer, thanks. (You could have implemented additional parsing, hence the question.)

Edited by pritaeas

0

Dani, another question concerning these two GET requests:

http://www.daniweb.com/api/members/1;94719?access_token=MYACCESSTOKEN http://www.daniweb.com/api/members/1;94719?page=2&access_token=MYACCESSTOKEN 

The first returns data for you and me. I'd expect the second to return 400 bad request since there is no page 2 (in line with other requests), but it appears to return random data (perhaps page 2 of all members).

With the following two:

http://www.daniweb.com/api/posts/vote?vote=1&access_token=MYACCESSTOKEN http://www.daniweb.com/api/articles/watch?access_token=MYACCESSTOKEN 

I actually expected 400 bad request for both (I know they're incomplete). Instead it returns JSON data containing {success: false}. Inconsistent with the rest as I never used a callback parameter for JSONP.

(Almost through my tests, so hope to be done soon with the whining.)

Edited by pritaeas

1

The first returns data for you and me. I'd expect the second to return 400 bad request since there is no page 2 (in line with other requests), but it appears to return random data (perhaps page 2 of all members).

Right, that's exactly what's happening. It's a bug.

I actually expected 400 bad request for both (I know they're incomplete). Instead it returns JSON data containing {success: false}. Inconsistent with the rest as I never used a callback parameter for JSONP.

Let me do some research and investigate the appropriate response for failed POST requests. I know when using JSONP you need to return JSON data since Javascript can't successfully interpret http status codes, but let me investigate whether we're currently doing the best thing for regular JSON POST requests. Odds are I'll switch this later tonight to a 400 error as you suggest. I have that other bug to squash too.

0

The first returns data for you and me. I'd expect the second to return 400 bad request since there is no page 2 (in line with other requests), but it appears to return random data (perhaps page 2 of all members).

If you're referring to the same issue - I think it was asked here: http://www.daniweb.com/community-center/daniweb-community-feedback/threads/451876/daniweb-api-page-parameter

And it seems to be a bug.

WRT to vote, I noticed that the upvote wasn't cancelled by a downvote on the same post. Is that reproducible?

0

Odds are I'll switch this later tonight to a 400 error as you suggest. I have that other bug to squash too.

Am done for tonight anyway, testing is a bitch.

If you're referring to the same issue

Indeed, missed that part or I'd have replied there.

I noticed that the upvote wasn't cancelled by a downvote on the same post. Is that reproducible?

Almost at that part, so not tested it yet.

Edited by pritaeas

1

I noticed that the upvote wasn't cancelled by a downvote on the same post. Is that reproducible?

Yes, it is reproducible. Once voted, a second call (up or down) returns a JSON success false. So with the API you cannot revoke your choice at the moment.

0

For the "Fetch Posts" the sample URL's given are:

Does that imply that filter can only be used on the last one? It appears so, just like it confirmed. If so, is it similar with the forum_id in the "Fetch Articles" call for a member?

Oh, and pasting lines of links in a code block formats without newlines.

Edited by pritaeas

0

Once voted, a second call (up or down) returns a JSON success false.

Addon: I just noticed that even though I have manually removed the vote on the OP (in this thread) manually, voting through the API no longer works. It returns a JSON result with success == false.

0

I think I know what's wrong but I won't be able to fix it until later tonight or tomorrow. In the meantime, please code your app as if it were working. I'll get it fixed as soon as I can. Unfortunately I have to go run the DaniWeb meetup group right now! :)

1

Don't worry, I'm still testing/extending the wrapper, so no issue for me. I'll add a comment in code.

1

It's always going to be descending order by timestamp. The difference is that firstpost examines the timestamp of the first post in the thread and lastpost examines the timestamp of the last post in the thread.

Will investigate closer and see if there is a bug here.

This question has already been answered. 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.