ljuhrich
31st May 2013, 20:23
Hi there,
I recently wanted to write a tool exploring the data which is requestable in facebook's Graph API. However, I created a tool performing a minimal request of the user's id and name.
The code is as following:
void MainWindow::doRequest()
{
// Read username, access token
QString id = QString(ui->edUserID->text());
QString access_token = QString(ui->edAcessToken->text());
socket = new QSslSocket(this);
QString data = "GET https://graph.facebook.com/"
+ id
+ "?fields=id,name,about&method=GET&format=json&access_token="
+ QUrl::toPercentEncoding( access_token )
+ " HTTP/1.1\r\n"
+ "Host: graph.facebook.com\r\n"
+ "Connection: Keep-alive\r\n"
+ "Accept-Encoding: gzip,deflate\r\n"
+ "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0\r\n"
+ "Accept: */*\r\n"
+ "\r\n"
;
connect(socket, SIGNAL(readyRead()), this, SLOT(resp()));
socket->connectToHostEncrypted("graph.facebook.com", 443);
if (!socket->waitForEncrypted())
{
ui->edResponse->setText(socket->errorString());
}
socket->write(data.toAscii());
}
void MainWindow::resp()
{
QString responseData;
QString tmp = QString(socket->readAll().data());
responseData += tmp;
ui->edResponse->setText( ui->edResponse->toPlainText() + "\r\n" + responseData);
}
With that code i get a response as following:
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, must-revalidate
Content-Type: application/json; charset=UTF-8
ETag: "581d7bde213d9c05777d0b6355eb626070e238fe"
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Pragma: no-cache
X-FB-Rev: 831988
X-FB-Debug: GGFSORJxReaKTcVhWmvBe6iBZoQTLyjEFm++YDBAGwM=
Date: Fri, 31 May 2013 18:11:07 GMT
Connection: keep-alive
Content-Length: 58
{
"id": "100002634417763",
"name": "Lukas Juhrich"
}
So far, so well.
But when I add some property fields, e.g. “sports,likes,interests†(added right after the “about†in the request string), the response gets damaged, although the very same request made by facebook's graph-explorer tool returned a correct result:
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, must-revalidate
Content-Type: application/json; charset=UTF-8
ETag: "d8e5cc3516f63acfeebc1a4db5b4a56b92809b7c"
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Pragma: no-cache
X-FB-Rev: 831988
Content-Encoding: gzip
X-FB-Debug: mm/FphJrwWeme7wz/uyv2FiadQxR6TdJXA//z7xgTnw=
Date: Fri, 31 May 2013 18:14:51 GMT
Connection: keep-alive
Content-Length: 10612
‹
¬Ãtôµéªszð¾c]¾ÙûéêøÃ{•^
Ìîʓ+ï±µ’7;Q•ô ŒKk}É8AUHHHQ$õùú÷oµªT• luÂTA`ÂÃ@"þ›È8‘©Ò¤T‡x³e pêà :ûq‘S÷‡{ÆÃÚ¹ ¤n+ÃÙ7ªÀŠ&•ïT»5´`*¡/•‰+˜µ[h$ÔúŽ£q9öël¥ŽÂŒ „ÂúÂMAvKäN´’ˣߠS¹ÔyQö<¡¼Ã1—•Ôç—láªZ µÃŸÂ⾻`—z$`$Qôâö …)wn!Ôdˆ§‹KW`§¯“Y¾ ·®t{?½ŸŒÒ¨gÃ*Ÿ\¼ kþ„i_-V=DX±˜W¬«V:¬š,#ò¦™ ί.ë+“h£BUÖ}¿„â2-ŹÎã{•ëéêþZ¨à –è îK3¡¾ÞX¿LAªÛî’x‰>ºæjv9Èâ
¾<©Šµïî0Yª£Ge‘¶P4’ ØQãâ}´¬¦
wCÂC4ƒLÆÂïˆ`ºs´ïW“4¥Ú*TÂ#ç¶Â0¾nôQÂœÊ1Ó8nm嬗%Ê#Ã…)%ß"Â…nB7ÒÞ\=¬óxQ
£Stûg%«ªæ ¤a
£)¨ya²ÆóQ“£´vÇê #`+EyñÃTs!Eç!Ã*H—¦¿² ?<AÓ¤bÂM¹¢“š»Tµæh~R ¥ŠEµ©%ýŠ×»4nßô>Ã’Z÷NÂ~}«$ \®º#kÆó1#WjܙV¾Óà øÃ1ô‹þz’†ù*ªÿV¾ûˆ6"¢m†\Ó(ÂŽsßÀ4Éՙ 9Ã*¿©U¾ÑÅ:Ön2,:ä ¤Â¦fEüb·œ¯¼ÖnÙ !N ºö)ˆ'ž šTÿö¡• ñ
*(SP©³¥8ZSöÄfKf:°£qDà 82FžÀ5ø$SØI|0ò°Ӥ —.sdiƲ'Z!ê^!®Ø¯€ ÀÖ<ÚmÀ¯ì‹T«$-氅jÀ¯8©ËâQ ÞHS_ÃÕo;‰–=¦Øy:Ù¹ £d;É*4 ×õ°VOmÂv°¿z§ÃrZÀà $Â¥z˜^’Úæ¦<(¢dJˆ¨;( Ãœ_Róª<’”T7b)5o)¿Ì)T ª)ñW3öîHö*ÞÃ
·Ã*ÿ Q P ÂϛfÃJ”jR½hn£j‚Ä\ ¦ÖU”¡ð¢8n ÂMç0î)Ã(‘ÂÓÂە# azȢF êØ*8û&"Ã¥w7}R1–Pý¦ÓÃ^asèåó ÂÃ*ÔB¨ÂÃʬÈ4}AÊKÃ*à ” Â’ÃNðPbÕ=¦â˜‘wm˜oà ºczHGÃ’~ú3Ã’2Yš©nb6J€3V66à ‘ey¥†,ç•ÓèöÙ.à µ<˜··H©]•Ö®ñxByžÊF6$óAÃŒJMà ŽpW¹ìÒêÂ4û¡+ý†yG y膎õª2'É;Ñò[H¡¡&õ*êÂHy
–ÞôòÃ@?Ã*äs:±®‰¾ šB,*)£«ÂÀ·t%žtPR=U*Ë tÆOãwu6j<ò«·=ùŽ¡üE“ÃY×
Do you have any kind of idea / tips etc. for me? thank you! :)
I recently wanted to write a tool exploring the data which is requestable in facebook's Graph API. However, I created a tool performing a minimal request of the user's id and name.
The code is as following:
void MainWindow::doRequest()
{
// Read username, access token
QString id = QString(ui->edUserID->text());
QString access_token = QString(ui->edAcessToken->text());
socket = new QSslSocket(this);
QString data = "GET https://graph.facebook.com/"
+ id
+ "?fields=id,name,about&method=GET&format=json&access_token="
+ QUrl::toPercentEncoding( access_token )
+ " HTTP/1.1\r\n"
+ "Host: graph.facebook.com\r\n"
+ "Connection: Keep-alive\r\n"
+ "Accept-Encoding: gzip,deflate\r\n"
+ "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:21.0) Gecko/20100101 Firefox/21.0\r\n"
+ "Accept: */*\r\n"
+ "\r\n"
;
connect(socket, SIGNAL(readyRead()), this, SLOT(resp()));
socket->connectToHostEncrypted("graph.facebook.com", 443);
if (!socket->waitForEncrypted())
{
ui->edResponse->setText(socket->errorString());
}
socket->write(data.toAscii());
}
void MainWindow::resp()
{
QString responseData;
QString tmp = QString(socket->readAll().data());
responseData += tmp;
ui->edResponse->setText( ui->edResponse->toPlainText() + "\r\n" + responseData);
}
With that code i get a response as following:
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, must-revalidate
Content-Type: application/json; charset=UTF-8
ETag: "581d7bde213d9c05777d0b6355eb626070e238fe"
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Pragma: no-cache
X-FB-Rev: 831988
X-FB-Debug: GGFSORJxReaKTcVhWmvBe6iBZoQTLyjEFm++YDBAGwM=
Date: Fri, 31 May 2013 18:11:07 GMT
Connection: keep-alive
Content-Length: 58
{
"id": "100002634417763",
"name": "Lukas Juhrich"
}
So far, so well.
But when I add some property fields, e.g. “sports,likes,interests†(added right after the “about†in the request string), the response gets damaged, although the very same request made by facebook's graph-explorer tool returned a correct result:
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, must-revalidate
Content-Type: application/json; charset=UTF-8
ETag: "d8e5cc3516f63acfeebc1a4db5b4a56b92809b7c"
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Pragma: no-cache
X-FB-Rev: 831988
Content-Encoding: gzip
X-FB-Debug: mm/FphJrwWeme7wz/uyv2FiadQxR6TdJXA//z7xgTnw=
Date: Fri, 31 May 2013 18:14:51 GMT
Connection: keep-alive
Content-Length: 10612
‹
¬Ãtôµéªszð¾c]¾ÙûéêøÃ{•^
Ìîʓ+ï±µ’7;Q•ô ŒKk}É8AUHHHQ$õùú÷oµªT• luÂTA`ÂÃ@"þ›È8‘©Ò¤T‡x³e pêà :ûq‘S÷‡{ÆÃÚ¹ ¤n+ÃÙ7ªÀŠ&•ïT»5´`*¡/•‰+˜µ[h$ÔúŽ£q9öël¥ŽÂŒ „ÂúÂMAvKäN´’ˣߠS¹ÔyQö<¡¼Ã1—•Ôç—láªZ µÃŸÂ⾻`—z$`$Qôâö …)wn!Ôdˆ§‹KW`§¯“Y¾ ·®t{?½ŸŒÒ¨gÃ*Ÿ\¼ kþ„i_-V=DX±˜W¬«V:¬š,#ò¦™ ί.ë+“h£BUÖ}¿„â2-ŹÎã{•ëéêþZ¨à –è îK3¡¾ÞX¿LAªÛî’x‰>ºæjv9Èâ
¾<©Šµïî0Yª£Ge‘¶P4’ ØQãâ}´¬¦
wCÂC4ƒLÆÂïˆ`ºs´ïW“4¥Ú*TÂ#ç¶Â0¾nôQÂœÊ1Ó8nm嬗%Ê#Ã…)%ß"Â…nB7ÒÞ\=¬óxQ
£Stûg%«ªæ ¤a
£)¨ya²ÆóQ“£´vÇê #`+EyñÃTs!Eç!Ã*H—¦¿² ?<AÓ¤bÂM¹¢“š»Tµæh~R ¥ŠEµ©%ýŠ×»4nßô>Ã’Z÷NÂ~}«$ \®º#kÆó1#WjܙV¾Óà øÃ1ô‹þz’†ù*ªÿV¾ûˆ6"¢m†\Ó(ÂŽsßÀ4Éՙ 9Ã*¿©U¾ÑÅ:Ön2,:ä ¤Â¦fEüb·œ¯¼ÖnÙ !N ºö)ˆ'ž šTÿö¡• ñ
*(SP©³¥8ZSöÄfKf:°£qDà 82FžÀ5ø$SØI|0ò°Ӥ —.sdiƲ'Z!ê^!®Ø¯€ ÀÖ<ÚmÀ¯ì‹T«$-氅jÀ¯8©ËâQ ÞHS_ÃÕo;‰–=¦Øy:Ù¹ £d;É*4 ×õ°VOmÂv°¿z§ÃrZÀà $Â¥z˜^’Úæ¦<(¢dJˆ¨;( Ãœ_Róª<’”T7b)5o)¿Ì)T ª)ñW3öîHö*ÞÃ
·Ã*ÿ Q P ÂϛfÃJ”jR½hn£j‚Ä\ ¦ÖU”¡ð¢8n ÂMç0î)Ã(‘ÂÓÂە# azȢF êØ*8û&"Ã¥w7}R1–Pý¦ÓÃ^asèåó ÂÃ*ÔB¨ÂÃʬÈ4}AÊKÃ*à ” Â’ÃNðPbÕ=¦â˜‘wm˜oà ºczHGÃ’~ú3Ã’2Yš©nb6J€3V66à ‘ey¥†,ç•ÓèöÙ.à µ<˜··H©]•Ö®ñxByžÊF6$óAÃŒJMà ŽpW¹ìÒêÂ4û¡+ý†yG y膎õª2'É;Ñò[H¡¡&õ*êÂHy
–ÞôòÃ@?Ã*äs:±®‰¾ šB,*)£«ÂÀ·t%žtPR=U*Ë tÆOãwu6j<ò«·=ùŽ¡üE“ÃY×
Do you have any kind of idea / tips etc. for me? thank you! :)