【问题标题】:C++ SDK for MTurk GetAccountBalance API call用于 MTurk GetAccountBalance API 调用的 C++ SDK
【发布时间】:2017-06-02 13:08:31
【问题描述】:

我对 C++ 有点陌生,根本没有使用过 SDK。我正在尝试在 Visual Studio 2013 中使用 C++ 重新创建 MTurk 请求者站点的开发人员页面上提供的示例 API 调用,该调用应该从沙箱返回帐户余额。 以下是 Python 的示例,从开发人员页面复制而来:

    import boto3

    region_name = 'us-east-1'
    aws_access_key_id = 'YOUR_ACCESS_ID'
    aws_secret_access_key = 'YOUR_SECRET_KEY'

    endpoint_url = 'https://mturk-requester-sandbox.us-east-1.amazonaws.com'

    # Uncomment this line to use in production
    # endpoint_url = 'https://mturk-requester.us-east-1.amazonaws.com'

    client = boto3.client('mturk',
        endpoint_url = endpoint_url,
        region_name = region_name,
        aws_access_key_id = aws_access_key_id,
        aws_secret_access_key = aws_secret_access_key,
    )

    # This will return $10,000.00 in the MTurk Developer Sandbox
    print client.get_account_balance()['AvailableBalance']

到目前为止,我已经写了这个:

    #include <aws/core/Aws.h>
    #include <aws/core/auth/awscredentialsprovider.h>
    #include <aws/mturk-requester/MTurkClient.h>
    #include <aws/core/client/ClientConfiguration.h>
    #include <aws/mturk-requester/model/getaccountbalancerequest.h>
    #include <aws/mturk-requester/model/getaccountbalanceresult.h>
    #include <aws/core/utils/Outcome.h>
    #include <aws/core/http/HttpRequest.h>
    #include <iostream>

    using std::string;
    using std::cout; using std::endl;
    using namespace Aws::Auth;
    using namespace Aws::MTurk;
    using namespace Aws::MTurk::Model;
    using namespace Aws::Client;

    int main(){
        Aws::SDKOptions options;
        Aws::InitAPI(options);

        const char* access_key = "my key"; //I put the right keys in
        const char* secret_access_key = "my secret key";

        ClientConfiguration config;
        config.region = "us_east_1";
        config.endpointOverride = "https://mturk-requester-sandbox.us-east-1.amazonaws.com";
        //Not sure if I need this to force sandbox mode

        //Uncomment this line to use in production
        //config.endpointOverride = "https://mturk-requester.us-east-1.amazonaws.com"

        AWSCredentials creds;
        creds.SetAWSAccessKeyId(access_key);
        creds.SetAWSSecretKey(secret_access_key);
        creds.SetSessionToken("");

        MTurkClient requester = MTurkClient(creds, config);

        //not entirely sure what to do from here:
        GetAccountBalanceResult bal;
        //const GetAccountBalanceRequest& request = GetAccountBalanceRequest();
        //bal.SetAvailableBalance(); If I set it, it'll return what I set

        //This should return $10, 000.00 in the MTurk Developer Sandbox
        cout << bal.GetAvailableBalance() << endl; //outputs empty string
        cout << config.region << endl; //outputs us_east_1
        //requester.GetAccountBalance(request); I feel like this is what I should be using to get the balance?
        cout << creds.GetAWSAccessKeyId() << endl; //outputs the right key

        system("pause");

        Aws::ShutdownAPI(options);
        return 0;
    }

像这样,代码编译并运行带有注释的输出。我查看了AWS SDK for C++documentation,以及 SDK .cpp 和 .h 文件本身。 有关使用 SDK 向网站发送信息的任何帮助也会有所帮助!

【问题讨论】:

    标签: c++ visual-studio mechanicalturk aws-sdk-cpp


    【解决方案1】:

    您可以通过以下方式打开日志: Aws::SDKOptions options; options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info; 也建议将sdk相关代码放入括号中: InitAPI { //your code here } ShutdownAPI

    你需要类似的东西: GetAccountBalanceOutcome outcome = client->GetAccountBalance(request)

    API 始终位于 {ServiceName}Client.h 中。 检查这个 S3 示例https://github.com/singku/aws-sdk-cpp-test

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多