#include <twit/Twitter.h>
#include <stdio.h>
#if defined(WIN32)||defined(_WIN32)
# if _DEBUG
# pragma comment(lib,"../../../lib/twit4cppd.lib")
# else
# pragma comment(lib, "../../lib/twit4cpp.lib")
# endif
#endif
using namespace std;
using namespace Twit;
int main(int argc, char* argv[])
{
/* twit4cpp Sample Application */
try
{
string
customerKey("2rBtCAh5o10zMlS2FbRYAA"),
customerSecert("MoZvHvDGbi6zoPu6Q1SZHsalGynP8qWt9dlB1NKlvQg");
string
aToken("access token"),
aSecret("access token secret");
Twitter twit(customerKey, customerSecert);
twit.setAccessToken(aToken, aSecret);
Resource::CDirectMessages& dm = twit.DirectMessages;
/***
* 받은 다이렉트 메시지
*/
Value::DirectMessages val = dm.DirectMessages.get();
for(size_t i=0; i<val.size(); i++)
{
Value::DirectMessage& dMsg = val[i];
printf("recipient : %s\n", dMsg.getRecipientScreenName().c_str());
printf("sender : %s\n", dMsg.getSenderScreenName().c_str());
wprintf(L"text : %s\n", dMsg.getText().c_str());
}
/***
* 보낸 다이렉트 메시지
*/
val = dm.Sent.get();
for(size_t i=0; i<val.size(); i++)
{
Value::DirectMessage& dMsg = val[i];
printf("recipient : %s\n", dMsg.getRecipientScreenName().c_str());
printf("sender : %s\n", dMsg.getSenderScreenName().c_str());
wprintf(L"text : %s\n", dMsg.getText().c_str());
}
Value::UniqueID dmId;
/***
* 다이렉트 메시지 보내기
*/
if(dm.New.request(string("screen_name"), L"hello! goodbye!"))
{
Value::DirectMessage& result = dm.New.value();
dmId = result.getId();
printf("new success\n");
printf("direct message id : %s\n", result.getId().toString().c_str());
printf("created at : %s\n", result.getCreatedAt().toString().c_str());
}
else
{
const Error& e = dm.New.getError();
printf("New error message : %s\n", e.getMessage().c_str());
printf("New error code : %d\n", e.getCode());
}
/***
* 다이렉트 메시지 삭제
*/
if(dm.Destroy.request(dmId))
{
Value::DirectMessage& result = dm.Destroy.value();
printf("destroy success\n");
printf("direct message id : %s\n", result.getId().toString().c_str());
printf("created at : %s\n", result.getCreatedAt().toString().c_str());
}
else
{
const Error& e = dm.Destroy.getError();
printf("Destroy error message : %s\n", e.getMessage().c_str());
printf("Destroy error code : %d\n", e.getCode());
}
}
catch(const Error& e)
{
printf("code : %d\n", e.getCode());
printf("message : %s\n", e.getMessage().c_str());
}
return 0;
}
* twit4cpp source