chr-1x / twc

A C99-compatible library for using the Twitter API from cURL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

twc_Statuses_Update fails with error code 44

opened this issue · comments

Can you confirm this issue on your end?
My test code is as follows:

        auto tweet = "looks like @chronaldragon's twc is working :) (this tweet sent from a #dlang script)";
        enforce(twc_statuses_updatee_params.init.MediaIds == null);
        twc_call_result x = twc_Statuses_Update(&twitter, twc_ToString(tweet.toStringz),
                twc_statuses_updatee_params.init);
        writefln("%s", x.ErrorStr.Ptr[0..x.ErrorStr.Size]);

The response:

{"errors":[{"code":44,"message":"media_ids parameter is invalid."}]}

I am not reproing on linux, see https://twitter.com/chronaldragon/status/821839149569228801

media_ids should not be included in the request if the member of the struct is null. I'm not familiar with D, is null there wrapped or anything?

I'd also recommend pulling down the latest revision from the repository, a few bugs were fixed last night that could affect the outcome of calls.

Hmm, no, null is 0, I'll try pulling the latest and report back

Updated to the latest and changed the code to this:

        auto tweet = "looks like @chronaldragon's twc is working :) (this tweet sent from a #dlang script)";
        auto test = twc_statuses_update_params.init;
        test.MediaIds = cast(const(char)*)0;
        twc_call_result x = twc_Statuses_Update(&twitter, twc_ToString(tweet.toStringz),
                test);
        writefln("%s", x.ErrorStr.Ptr[0..x.ErrorStr.Size]);

same response.

These are my bindings:

extern(C) {
    struct CURL;
    struct twc_strbuf {
        size_t Size;
        char* Ptr; }
    struct twc_buffer {
        size_t Size;
        void* Ptr; }
    struct twc_string {
        size_t Size;
        const(char)* Ptr; }
    struct twc_oauth_keys {
        const(char)* ConsumerKey;
        const(char)* ConsumerSecret;
        const(char)* TokenKey;
        const(char)* TokenSecret; }
    alias twc_malloc_func = void* function(size_t);
    alias twc_free_func = void function(void*);
    struct twc_state {
        twc_malloc_func MemAllocFunc;
        twc_free_func MemFreeFunc;
        CURL* cURL;
        twc_strbuf cURL_Error;
        twc_buffer cURL_Data;
        twc_buffer cURL_HeaderBuf;
        twc_oauth_keys Keys; }
    alias twc_error = int;
    struct twc_call_result {
        twc_error Error;
        union {
            twc_buffer Data;
            twc_string ErrorStr; } }
    alias twc_status_id = ulong;
    alias twc_place_id = ulong;
    pragma(mangle, "bool$") struct bool_ {
        bool Exists;
        bool Value; }
    pragma(mangle, "twc_string$") struct twc_string_ {
        bool Exists;
        bool Value; }
    pragma(mangle, "twc_status_id$") struct twc_status_id_ {
        bool Exists;
        twc_status_id Value; }
    pragma(mangle, "twc_place_id$") struct twc_place_id_ {
        bool Exists;
        twc_place_id Value; }
    struct twc_account_verifycredentials_params {
        bool_ IncludeEntities;
        bool_ SkipStatus;
        bool_ IncludeEmail; }
    struct twc_statuses_update_params {
        twc_status_id_ InReplyToStatusId;
        bool_ PossiblySensitive;
        twc_string_ Lat;
        twc_string_ Long;
        twc_place_id_ PlaceId;
        bool_ DisplayCoordinates;
        bool_ TrimUser;
        const(char)* MediaIds; }
    void twc_Init(twc_state*, twc_oauth_keys);
    twc_string twc_ToString(const(char)*);
    twc_call_result twc_Account_VerifyCredentials(twc_state*, twc_account_verifycredentials_params);
    twc_call_result twc_Statuses_Update(twc_state*, twc_string, twc_statuses_update_params);
}

I'm going to try writing a test in C and will see if the same thing happens

Not sure how to compile this test in C:

#include <stdio.h>
#include "twitter.h"
#include "twitter_api.h"
//keys/secrets redacted
int main(int argc, char *argv[])
{
    twc_oauth_keys keys = { CONSUMER_KEY, CONSUMER_SECRET, TOKEN_KEY, TOKEN_SECRET };
    twc_state twitter;
    twc_Init(&twitter, keys);
    const char* tweet = "looks like @chronaldragon's twc is working from C";
    twc_statuses_update_params test = {0};
    twc_call_result x = twc_Statuses_Update(&twitter, twc_ToString(tweet),
            test);
    printf("%.*s\n", x->ErrorStr.Size, x->ErrorStr.Ptr);
    return 0;
}

I get a big wall of errors if I include twitter_api.h and if I just include twitter.h I am missing twc_statuses_update_params

I have not used D, but this seems suspect:

    pragma(mangle, "twc_string$") struct twc_string_ {
        bool Exists;
        bool Value; }

Shouldn't Value be a twc_string?

@miotatsu you should only need to include "twitter.h". If that struct name is missing you may need to redownload twitter_api.h/.c or re-run the code generator, since there was a buffer overflow problem causing the wrong names to be created sometimes, and I had pushed versions of the _api.h/.c files with that problem to the repo without noticing. The versions in there now have this fixed.
I'm not certain that I don't also have another bug which exists only on some platforms regarding the name generation, so if the versions that the code generator is building for you still have problems, please post an issue about it with compiler/platform so I can trace down the issue.

Amendment to the earlier statements:

  • Codegen problem is still reproing on Windows
  • The files in the include/ folder haven't been getting updated, so that's probably why you still can't use the proper name for the statuses/update param struct (temp fix until I get another push out: use the ones from code/. I need to change the build process so that I only keep around one copy of these)

@baines hit the nail on the head, that binding was incorrect causing the size of my struct to mismatch the actual. Changing from bool to twc_string fixed the problem! https://twitter.com/miotatsu/status/821932817663856640

Not going to bother getting the C test working as we found the problem