用于 MTurk GetAccountBalance API 调用的 C++ SDK
C++ SDK for MTurk GetAccountBalance API call
我对 C++ 有点陌生,完全没有使用过 SDK。我正在尝试在 Visual Studio 2013 年使用 C++ 重新创建示例 API 在 MTurk 请求者网站的开发者页面上提供的调用,该调用应该 return 来自沙盒的帐户余额。
这是 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 ,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 , 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++, the documentation,还查看了 SDK .cpp 和 .h 文件本身。
任何有关使用 SDK 将信息发送到网站的帮助也会有所帮助!
您可以通过以下方式打开日志:
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
我对 C++ 有点陌生,完全没有使用过 SDK。我正在尝试在 Visual Studio 2013 年使用 C++ 重新创建示例 API 在 MTurk 请求者网站的开发者页面上提供的调用,该调用应该 return 来自沙盒的帐户余额。 这是 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 ,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 , 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++, the documentation,还查看了 SDK .cpp 和 .h 文件本身。 任何有关使用 SDK 将信息发送到网站的帮助也会有所帮助!
您可以通过以下方式打开日志:
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