Facebook Graph API: result in array or in json object - facebook

I have little bit confuse between graph api result.Can any one explain which default object method is facebook using when we fetch data via graph api. Have any application account setting for access data in json object or in array object, because some time i found user data in encrypted and some time non encrypted.
I found user email id in two way from facebook graph api.
One is:
{
"id": "100001114785800",
"name": "Stella Jackson",
"first_name": "Stella",
"last_name": "Jackson",
"link": "http://www.facebook.com/profile.php?id=100001114785800",
"birthday": "04/16/1987",
"gender": "female",
"email": "stella_ja#live.com",
"timezone": 5.5,
"locale": "en_US",
"updated_time": "2010-10-08T13:26:10+0000"
}
And second one is:
{
"id": "100001114785800",
"name": "Stella Jackson",
"first_name": "Stella",
"last_name": "Jackson",
"link": "http://www.facebook.com/profile.php?id=100001114785800",
"birthday": "04/16/1987",
"gender": "female",
"email": "stella_ja\u0040live.com",
"timezone": 5.5,
"locale": "en_US",
"updated_time": "2010-10-08T13:26:10+0000"
}
Have any idea?
Thanks

The '\u0040' is same as obfuscated or Unicode form of '#' symbol. Most Parsers can convert that to the original symbol.
Check this for list of Unicode character set.
http://www.alanwood.net/demos/ansi.html

#Vik i want to do the same thing, collect post info in array, try this if it work than see..
if (response.authResponse) {
var accessToken = response.authResponse.accessToken;
//var UserInfo = document.getElementById('UserInfo');
FB.api('/' + info.id + '/feed?access_token=' + accessToken,
{ limit: 20 },function(result) {
UserInfo.innerHTML = "Welcome, " + result.id + "!";
alert('Message: ' + result.id);
});
}

Use this to get the dictionary n value of email for ios
FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:#"me" withGetVars:nil];
NSLog(#"getMeButtonPressed: %#", fb_graph_response.htmlResponse);
NSDictionary *dictionary=[fb_graph_response.htmlResponse JSONValue];
NSLog(#"%#",[dictionary valueForKey:#"email"]);
Hope it helps you.

The easiest way would be to take the email string and do something like this (objective c):
NSString *email = #"stella_ja\u0040live.com"; // or whatever you use to get it
email = [NSString stringByReplacingOccurencesOfString:#"\u0040" withString:#"#"];
So in other words, use string methods to replace "\u0040" with "#".

you can simply replace \u0040 with # but during this replace compiler will consider "\" as escape sequence and will skip this without making changes.
What you do like this below:
NSString *strEmail = #"stella_ja\u0040live.com";
[strEmail stringByReplacingOccurrencesOfString:#"\\u0040" withString:#"#"];
NSLog(#"strEmail: %#", strEmail);

Related

Instagram API response with users not in caption

I want to know what users are tagged in a photo on Instagram, who don't appear in the caption.
Anyone know if this is possible? That is, does the response contain users that are tagged, but that are not physically in the caption text?
https://www.instagram.com/developer/endpoints/tags/
The property you probably want is called users_in_photo. It is an array which contains an array of user objects who've been tagged in the photo. It also contains the geometric coordinates in the photo that the user has been "tagged" at.
Here is an example response using the /media/MEDIA_ID endpoint:
Endpoint Documentation -> https://www.instagram.com/developer/endpoints/media/#get_media
{
"data": {
"users_in_photo": [{
"user": {
"username": "kevin",
"full_name": "Kevin S",
"id": "3",
"profile_picture": "..."
},
"position": {
"x": 0.315,
"y": 0.9111
}
}],
// rest of object...
}
}
I think what you are looking for are username mentions in captions and comments, API does not return this list in API, you will have to search for #usernames in the caption string.
You will have to make a separate API call to get the comments in post (u can only get latest 120), and do a manual string search in each of the comments.
users_in_photo in API response will have an array of users that are actually tagged on photo, not username mentions

Delphi XE5: Problems with proper visualization of extracted GMail emails

I am facing some trouble in properly visualizing emails extracted from GMail. I use the GMail API to retrieve the messages. This part seems to be working properly and I get the json with the entire message.
Here is a small part of one of the body parts
"mimeType": "multipart/alternative",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "multipart/alternative; boundary=001a114710d029267205278f13b9"
}
],
"body": {
"size": 0
},
"parts": [
{
{
"partId": "0.0",
"mimeType": "text/plain",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/plain; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 549,
"data": "SGkgUGF1bCwNCg0KQXBvbG9naWVzLCBidXQgSSBmb3Jnb3QgdG8gbWVudGlvbiB0aGF0IHRoZSByZXN0IG9mIHlvdXIgb3JkZXIgaGFzIGJlZW4NCnNlbnQgb3V0IGluIHRoZSBtZWFudGltZQ0KDQpNYW55IHRoYW5rcw0KDQoqS2luZCBSZWdhcmRzKg0KKkJhcmJhcmEgSm9uZXMqDQoqSW50ZXJuZXQgU2FsZXMqDQoNCipPbGQgTWlsbCBTYWRkbGVyeSoNCg0KKnd3dy5zYWRkbGVyeS5iaXogPGh0dHA6Ly93d3cuc2FkZGxlcnkuYml6Lz4qDQoNCipUZWw6ICs0NCAoMCkyOCA5MzM1IDMyNjggPCUyQjQ0JTIwJTI4MCUyOTI4JTIwOTMzNSUyMDMyNjg-Kg0KDQoqVGFrZSBhIFZpcnR1YWwgdG91ciBvZiBvdXIgc2hvcCoNCkdvb2dsZSBwbGFjZXMgaHR0cDovL2dvby5nbC85Y1o5ZDANCipbaW1hZ2U6IElubGluZSBpbWFnZXMgNF1XaXNoaW5nIHlvdSBhIHZlcnnigItbaW1hZ2U6IElubGluZSBpbWFnZXMgM10qDQoqICAgICAgICAgICAgICAgICAgTWVycnkgQ2hyaXN0bWFzKg0KDQoq4oCLICAg4oCLICDigIsgICAgW2ltYWdlOiBJbmxpbmUgaW1hZ2VzIDJd4oCLKg0K"
}
}
So what is the data part encoded with? I am getting confused with the "Content-Transfer-Encoding" ->"quoted-printable". Should I decode the value of the data using a "quoted-printable" decoder or not?
Initially without noticing the "quoted-printable" value, I decoded the data value using DecodeBase64, here is how I am making it
function TViewEmailsForm.DecodeData(aStr: String): String;
var
aStrm: TBytesStream;
aStrStrm: TStringStream;
begin
Result := '';
if aStr = '' then
Exit;
aStrm := TBytesStream.Create(DecodeBase64(aStr));
aStrStrm := TStringStream.Create;
try
aStrm.Position := 0;
aStrStrm.LoadFromStream(aStrm);
Result := aStrStrm.DataString;
finally
aStrm.Free;
aStrStrm.Free;
end;
end;
Using that returns human readable text, however at the end something more is decoded and I don't get what it is. I presume it is some kind of formatting bold text, link, kind of signature but I don't succeed in anyway to show it properly (not sure what to use though as component - RichEdit, HTMLViewer)
The end of the decoded string looks like
.......
*Name of the company*
*website of the company <again the website of the company>*
*Tel: +44 (0)28 9335 3268 <%2B44%20%280%2928%209335%203268
ѓBѓBЉ•ZЩHHљ\ќX[Э\€Щ€Э\€ЪЬ
ѓB‘ЫЫЩЫHXЩ\И‹ЛЩЫЫЛ™ЫОXЦЋYBЉ–Ъ[XYЩN€[›[™H[XYЩ\И
UЪ\Ъ[™И[ЭHH™\ћx "ЦЪ[XYЩN€[›[™H[XYЩ\ИЧJѓBЉ€Y\њћHЪљ\ЭX\КѓBѓBЉё "И8 "И8 "ИЪ[XYЩN€[›[™H[XYЩ\И—x "КѓB›
I have some other messages which pretend to have html body, but again the data is seen in that way. I tried to load this string into the lines of TRichEdit, but had no luck, I tried to use TIdDecoderQuotedPrintable to decode this string, though I am not sure if I have to make it, but some of the characters got replaced by '?' (question marks)
What I am missing here and what is the proper way of visualizing the content of the messages?
After serious research and testing different encoders/decoders I finally managed to properly decode what was encoded in the message.
I used Indy's TIdEncoderMIME found in IdCoderMIME and used the DecodeString method. The HTML messages and bodies are properly decoded too with it.
Hope this will help other people not to spend two days in "fighting" with decoding messages!
EDIT: I noticed that the symbol > comes as ? Maybe there something else which has to be done?
EDIT2: It seems that the encoding of the data is not actually Base64 but Base64Url. On the following link http://blog.marcocantu.com/blog/delphi_facebook_base64_encoding.html you can find interesting post on that. The images are encoded in that way and the standard decoding doesn't work for extracting them.
Whoever knows French can read something here too http://codes-sources.commentcamarche.net/source/51156-base64-base64url-encode-decode

Facebook object API - duplicate objects created

I am creating objects through the open graph object API, and attaching these to published stories. Both the object and the story are created, and FB returns id's as if everything worked out just fine.
However, while submitting the object/story for review it turned out two objects are created (of different object types) even though I only make one HTTP POST request.
Background
Our app is using namespace 'mynamespace'
We have created a custom open graph object with name 'myobject'
We have created a custom open graph action with name 'myaction'
Request details:
1) First we create an object:
POST /me/objects/mynamespace:myobject HTTP/1.1\r\nConnection: close\r\nHost: graph.facebook.com\r\nContent-Length: LENGTH\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n
URI decoded http body:
access_token=TOKEN&object={"url":"http://url.com","title":"My title","image":"https://imageurl.com","description":"My description"}
Response:
"{\"id\":\"123456789\"}"
2) Then we create a story (with this object referenced):
POST /me/mynamespace:myaction HTTP/1.1\r\nConnection: close\r\nHost: graph.facebook.com\r\nContent-Length: LENGHT\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n
URI decoded http body:
access_token=TOKEN&myobject=123456789&fb:explicitly_shared=true&message=User generated message
Response:
"{\"id\":\"12121212121\"}"
Expected result
One object of type mynamespace:myobject should be created
One story of type mynamespace:myaction should be created
Actual result
One object of type mynamespace:myobject is created
One story of type mynamespace:myaction is created
One object of type Object is created (according to reviewer)
One action of type Post is created (according to reviewer)
Only one story turned up in the user feed and in the object browser, but the reviewer told us following:
Your action produces more than one published story when the user triggers the action. Users shouldn’t be surprised by multiple stories being published for a single in-app action. The action I took produced a "post" and a "myaction" story.
We had a look under (Open Graph -> Types) and it turned out that each time we make this request an object of type 'Object' and an action of type 'Post' is automatically created/defined! This must be what the reviewer complains about, but we haven't been able to figure out what we're doing wrong!
Any suggestions on how this can be solved is be very much appreciated.
Exact same issue when using the Open Graph API explorer
Turns out the exact same thing happens when creating an object through the Facebook Graph API explorer. When doing so the 'Object' object and the 'Post' action suddenly appears under Open Graph -> Types. Right now I see following reasons to this issue:
The object/action/story is set up incorrect in some way
The reviewer thought it was an issue when it actually wasn't
It's a FB bug
Object(s) created through the Graph API explorer
When creating an object through the Graph API explorer this is the resulting object:
{
"id": "4324324234234234",
"url": "http://url.com",
"type": "mynamespace:myaction",
"title": "My title",
"image": [
{
"url": "https://imageurl.com"
}
],
"description": "My description",
"updated_time": "2013-07-09T14:14:38+0000",
"created_time": "2013-07-09T14:14:38+0000",
"application": {
"id": "432423423423",
"name": "appname",
"url": "https://www.facebook.com/apps/appurl"
},
"is_scraped": false,
"post_action_id": "23423423423423423"
}
The 'post_action_id' seems weird, and when requesting that object I get:
{
"id": "423423423423",
"from": {
"name": "My name",
"id": "234234"
},
"start_time": "2013-07-09T14:14:38+0000",
"end_time": "2013-07-09T14:14:38+0000",
"publish_time": "2013-07-09T14:14:38+0000",
"application": {
"name": "appname",
"namespace": "mynamespace",
"id": "432423423423"
},
"data": {
"object": {
"id": "4324324234234234",
"url": "http://url.com",
"type": "mynamespace:myaction",
"title": "My title"
}
},
"type": "og.posts",
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true,
"comment_order": "chronological"
}
}
The fact that the object already has a related og.posts object must be what the review think is the issue here. I still don't understand why this og.posts object automatically shows up as an open graph object though.
The issue here is that when the user clicks the "Peace" button on your site, two Open Graph actions are published and that's against our policy - one user action should not publish multiple stories. If you log in as your Open Graph Test User and check the Activity Log, you'll see the following two published actions with the same timestamp:
https://www.facebook.com/100006264788511/activity/1388570951361718
https://www.facebook.com/100006264788511/activity/1388570924695054
Are you sure your code is only making a single call to the Graph API when publishing the action?
I'm not sure how this would map to your POSTs, but I was dealing with the same issue on iOS and the problem is posting both the object and the action. If you set the object on the field other of the action (instead of the objectId after posting) only one Activity is created.
In my case, instead of doing:
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
object.provisionedForPost = YES;
object[#"title"] = #"Title";
object[#"type"] = #"video.other";
object[#"url"] = url;
[FBRequestConnection startForPostOpenGraphObject:object
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (!error && [result objectForKey:#"id"]) {
NSString* objectId = [result objectForKey:#"id"];
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
action[#"explicitly_shared"] = #"true";
action[#"other"] = objectId;
[FBRequestConnection startForPostWithGraphPath:#"me/myNamespace:post"
graphObject:action
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
// handle success and failures
}];
}
}];
I had to do:
NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
object.provisionedForPost = YES;
object[#"title"] = #"Title";
object[#"type"] = #"video.other";
object[#"url"] = url;
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
action[#"explicitly_shared"] = #"true";
action[#"other"] = object;
[FBRequestConnection startForPostWithGraphPath:#"me/myNamespace:post"
graphObject:action
completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
// handle success and failures
}];

Can i load the private photos with my webapp from facebook users?

I have a website and use the login using facebook.
I want to do the following:
User comes to my web site - login with facebook - I read his facebook data and photography permits
For example:
{
"id": "1"
"name": "John English"
"first_name": "John",
"last_name": "English"
"link": "https://www.facebook.com/johnenglish"
"username": "johnenglish"
"gender": "male"
"locale": "en_US"
....
}
and
{
"id": "2"
"name": "John English2"
"first_name": "John",
"last_name": "English2"
"link": "https://www.facebook.com/johnenglish2"
"username": "johnenglish2"
"gender": "male"
"locale": "en_US"
....
}
Both users have a private photo. Can I load the private photos from user (id: 2) with my web application using javascript? Can you give me the example?
I've tried this:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.api('/USER-ID(USER ID 2)/photos?access_token=' + accessToken, function(response) {
//A user access token is required to request this resource.
});
} else if (response.status === 'not_authorized') {
} else {
}
});
Error: A user access token is required to request this resource.
Have you requested the right permissions when you gained your access token? I don't know how to do it in JS, but you have to tell facebook, that you want you get access to the photos. As I do not work with JS, I request my access token via an URL (see Point 1 here: https://developers.facebook.com/docs/authentication/devices/). In the parameter "scope" you can add the permissions you want to have ( https://developers.facebook.com/docs/authentication/permissions/). Here, you add "&scope=user_photos" (without quotation marks) to the URL.
OK, now I understand your question.
I assume that you already found out the ID of the User 2. I am sorry but I can still not show you how to do it in JS. Though, it may help.
At first, I forgot one permission, you need friends_photos in scope, too.
You now call: http://graph.facebook.com/FRIEND_ID/albums/?access_token=ACCESS_TOKEN.
Type it into your browser, so that you know what I mean: You parse that output and find ids of the albums of your friend.
You get to that album via: http://graph.facebook.com/ALBUM_ID?access_token=ACCESS_TOKEN.
You will find an entry named cover_photo in your output.
Call: http://graph.facebook.com/COVER_PHOTO_ID?access_token=ACCESS_TOKEN and you get access to that photo.
You may now download it via http://graph.facebook.com/COVER_PHOTO_ID/picture?access_token=ACCESS_TOKEN.
Use the URL given in paging -> next to move on to the following photos. It is much easier to follow these steps with a picture in mind, consider that here.

Convert Facebook names to id numbers

I've noticed some difference in Facebook profiles :
Some of them have the following string format at browser nav bar :
http://facebook.com/john.smith
and the others look like this :
http://www.facebook.com/profile.php?id=100455*
Can someone explain why there is a difference ?
And more important is how can I convert those john.smith like names to id numbers ?
These are alias urls that Facebook offers its users (and pages) - its basically a vanity thing, both the id and the alias url will work the same way.
You can translate the alias (or username) by doing a lookup for that user using the Facebook Graph API. Simply make a GET request to https://graph.facebook.com/John for example - this will serve the following response:
{
"id": "779695190",
"name": "John Chan",
"first_name": "John",
"last_name": "Chan",
"link": "http://www.facebook.com/John",
"username": "John",
"gender": "male",
"locale": "en_US",
"updated_time": "2011-12-27T05:01:06+0000",
"type": "user"
}
response.id is what your interested in.
Test it out: http://developers.facebook.com/tools/explorer?method=GET&path=john
You're not really want to converting the ids to names but getting id by username which is possible by issuing request to Graph API:
GET https:/graph.facebook.com/john.smith?fields=id
Here is a JQuery based solution, where callback is an arbitrary function:
$.get("https://graph.facebook.com/" + name + "?fields=id", function(response){
if(response.error){
callback(false)
}else{
callback(response.id);
}
});