0

我对 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++文档以及 SDK .cpp 和 .h 文件本身。有关使用 SDK 向网站发送信息的任何帮助也会有所帮助!

4

1 回答 1

0

您可以通过以下方式打开日志: 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

于 2017-06-06T17:43:21.377 回答