2017-06-02 74 views
0

我对C++有点新鲜,根本没有使用SDK。我试图在Visual Studio 2013中使用C++重新创建MTurk请求者网站的开发者页面上提供的示例API调用,该页面应该从沙箱中返回帐户余额。 下面是蟒蛇的例子,复制关闭开发者页面的:C++ SDK for MTurk GetAccountBalance API调用

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将信息发送到网站的帮助也将有所帮助!

回答

0

您可以通过像打开日志: Aws::SDKOptions options; options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info; 还建议把SDK相关的代码放到支架: InitAPI { //your code here } ShutdownAPI

而且你需要的东西,如: GetAccountBalanceOutcome outcome = client->GetAccountBalance(request)

的API总是在{服务名称} Client.h。 检查此S3示例https://github.com/singku/aws-sdk-cpp-test