Hey guys,
I am totally new to Tweeter API, and I just started trying to write a c
++ app on the windows mobile to use the tweeter API. Just to get a
feel for things, I wrote the function below. I know it has a lot of
probs, but I just wanted to get something quick to see if I could talk
to the Tweeter API. So to start with, I am not even doing auth and
just try to get the status of 123. However, when I do the
InternetReadFile, I kept getting the following, which seems like part
of an html file. So if any1 has an idea on what I am doing wrong, plz
lemme know. (Btw, I am not using the urlencoded content-type because I
think it's not required for GET commands?) Thanks in advance.
----------------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Error Message</TITLE>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<STYLE id=L_11001_1>A {
FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: #005a80; FONT-FAMILY:
tahoma
}
A:hover {
FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: #0d3372; FONT-FAMILY:
tahoma
}
TD {
FONT-SIZE: 8pt; FONT-FAMILY: tahoma
}
TD.titleBorder {
BORDER-RIGHT: #955319 1px solid; BORDER-TOP: #955319 1px solid;
PADDING-LEFT: 8px; FONT-WEIGHT: bold; FONT-SIZE: 12pt; VERTICAL-ALIGN:
middle; BORDER-LEFT: #955319 0px solid; COLOR: #955319; BORDER-BOTTOM:
#955319 1px solid; FONT-FAMILY: tahoma; HEIGHT: 35px; BACKGROUND-
COLOR: #d2b87a; TEXT-ALIGN: left
}
TD.titleBorder_x {
BORDER-RIGHT: #955319 0px solid; BORDER-TOP: #955319
----------------------------------------------------------
int ConnectToTweeter()
{
HINTERNET hOpen = NULL, hConnect = NULL, hRequest = NULL;
LPTSTR hdrs = (L"Content-Type: application/x-www-form-urlencoded");
LPTSTR TwitterXMLUrl = (L"http://twitter.com/statuses/show/123.xml");
LPTSTR AcceptTypes[2] = {TEXT("Accept: */*"), NULL};
DWORD dwFlags = INTERNET_FLAG_KEEP_CONNECTION;
DWORD sizeInResult, sizeOutResult, sizeToWrite, sizeWritten;
LPDWORD pSizeInResult = &sizeInResult;
LPDWORD pSizeOutResult = &sizeOutResult;
LPDWORD pSizeToWrite = &sizeToWrite;
LPDWORD pSizeWritten = &sizeWritten;
LPVOID lpBuffer [1024];
TCHAR szErrMsg[200];
sizeToWrite = 200;
OpenFile();
if (!(hOpen = InternetOpen(TEXT("CeHttp"),
INTERNET_OPEN_TYPE_PRECONFIG , NULL, 0, 0)))
{
wsprintf (szErrMsg, TEXT("%s: %x"), TEXT("InternetOpen Error"),
GetLastError());
WriteFile (hFile, szErrMsg, sizeToWrite, pSizeWritten, NULL);
goto error;
}
if (!(hConnect = InternetConnect
(hOpen,TwitterXMLUrl,INTERNET_DEFAULT_HTTP_PORT,NULL,
NULL,INTERNET_SERVICE_HTTP,0,1)))
{
wsprintf (szErrMsg, TEXT("%s: %x"), TEXT("InternetConnect
Error"),
GetLastError());
WriteFile (hFile, szErrMsg, sizeToWrite, pSizeWritten, NULL);
goto error;
}
if (!(hRequest = HttpOpenRequest (hConnect,(L"GET"),NULL, NULL,
(LPCTSTR) AcceptTypes,NULL,dwFlags,0)))
{
wsprintf (szErrMsg, TEXT("%s: %x"), TEXT("HttpOpenRequest
Error"),
GetLastError());
WriteFile (hFile, szErrMsg, sizeToWrite, pSizeWritten, NULL);
goto error;
}
if (!(HttpSendRequest (hRequest, NULL, 0, NULL, 0)))
{
wsprintf (szErrMsg, TEXT("%s: %x"), TEXT("HttpSendRequest
Error"),
GetLastError());
WriteFile (hFile, szErrMsg, sizeToWrite, pSizeWritten, NULL);
goto error;
}
if (!(InternetQueryDataAvailable (hRequest, pSizeInResult, 0, 0)))
{
wsprintf (szErrMsg, TEXT("%s: %x"),
TEXT("InternetQueryDataAvailable
Error"), GetLastError());
WriteFile (hFile, szErrMsg, sizeToWrite, pSizeWritten, NULL);
goto error;
}
if (sizeInResult >= 1024)
{
int num = sizeInResult / 1024;
do
{
InternetReadFile (hRequest, lpBuffer, 1024,
pSizeOutResult);
WriteFile (hFile, lpBuffer, sizeOutResult,
pSizeWritten, NULL);
}
while (--num > 0);
}
else
{
InternetReadFile (hRequest, lpBuffer, sizeInResult,
pSizeOutResult);
WriteFile (hFile, lpBuffer, sizeOutResult, pSizeWritten, NULL);
}
CloseFile();
InternetCloseHandle(hOpen);
InternetCloseHandle(hConnect);
InternetCloseHandle(hRequest);
return 0;
error:
CloseFile();
InternetCloseHandle(hOpen);
InternetCloseHandle(hConnect);
InternetCloseHandle(hRequest);
return 1;
}