iOS can't send dictionary parameters in FBSDKGraphRequest - ios

I am trying to get the profile picture of a Facebook user in a reasonable quality from my app. By default, without any parameters, the request to the path "me?fields=picture" fetch the small one but using a parameters dictionary with the key #"type" and value #"large" would retrieve the large one. However, the api seems to be ignoring the parameters.
FBSDKGraphRequest* picRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:#"me?fields=picture" parameters:[NSDictionary dictionaryWithObject:#"small" forKey:#"type"] HTTPMethod:#"GET"];
[picRequest startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (result) {
NSString* profilePictureURLString = [[[(NSDictionary*) result objectForKey:#"picture"] objectForKey:#"data"] objectForKey:#"url"];
NSURL* profilePictureURL = [NSURL URLWithString:profilePictureURLString];
NSData* profilePictureData = [NSData dataWithContentsOfURL:profilePictureURL];
}];
The resulting data is always the small picture with 50x50 pixels.
Can somebody help me please? Thanks!

You can set the size of the picture like picture.width(float).height(float). See the example below:
FBSDKGraphRequest* picRequest = [[FBSDKGraphRequest alloc] initWithGraphPath:#"me?fields=picture.width(200).height(200)"
parameters:nil
HTTPMethod:#"GET"];
You can test the request into Graph API Explorer

Related

Fetch All Uploaded Images From Facebook in Ios?

I have use Facebook SDK for fetch photos but they provide us picture (for Profile Picture),cover(Cover Photo) but not provide me all photos of user. any one suggest me how to fetch all images from facebook.
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/{facebook id}/albums"
parameters:nil
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
// Insert your code here
}];
I use above code for get images but its returns no data.
any one have idea about this then please tell me. thanks in advance.

Facebook Graph API for pages using iOS SDK

I'm trying to retrieve the conversations that the page had with it's users/visitors. I was able to retrieve the conversations for the page using the below call. I do have the right page access token in the 'pgAccessToken' variable.
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:pgAccessToken forKey:#"access_token"];
[params setObject:#"fields" forKey:#"fields"];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/{page-id}/conversations"
parameters:nil tokenString:pgAccessToken
version:nil HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"Output : %#", result);
}];
I was able to receive a list of conversations.
{
"data": [
{
"created_time": "2015-12-12T02:24:21+0000",
"id": "m_mid.1449888061289:b3ec94g1ec0729d776"
},
{
"created_time": "2015-12-12T02:23:08+0000",
"id": "m_mid.1449887988645:94905084ecfdf89812"
}
],
"paging": {
"previous": "https://graph.facebook.com/v2.5/t_mid.1448167619182:200955bd99614aa136/messages?format=json&access_token={MYACCESSTOKEN}&limit=25&since=1449887061&__paging_token={MYPAGINGTOKEN}&__previous=1",
"next": "https://graph.facebook.com/v2.5/t_mid.1448167619182:2009335d99614aa136/messages?format=json&access_token={MYACCESSTOKEN}&limit=25&until=1448167619&__paging_token={MYPAGINGTOKEN}"
}
}
Now I'm trying to receive messages in the conversation. Which I can get by hitting the node '{conversation-id}/messages' but it just gives me a timestamp and message id as part of the response.
What I want is not just the time stamp and message id, but instead the from, to and message contents. I tried the Graph API Explorer but it would still return the same data when I use the following different nodes.
/{conversation-id}/messages
/{message-id}
Can any one help ?
++++UPDATE++++
FIGURED IT OUT. PASTED BELOW IS THE ANSWER IF SOMEBODY ELSE COMES ACROSS THE SAME ISSUE.
Finally figured this out after a few tries with Graph API Explorer tool on facebook developer page.
The way to get more fields is by supplying the fields I wanted in addition to the default that were being sent to me.
NSString *pgAccessToken = [[NSUserDefaults standardUserDefaults] objectForKey:#"PAGE_ACCESS_TOKEN"]; //I have my page accesstoken stored here.
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:#"message_count,updated_time,participants,snippet" forKey:#"fields"];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/{page-id}/conversations"
parameters:params tokenString:pgAccessToken
version:nil HTTPMethod:#"GET"];
__weak MessagesTableViewController *weakSelf = self;
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"Output : %#", result);
//Process your result here, add to local array, reload table etc.
}];

post google static map to facebook wall

I want to post a google static map to facebook wall
this is map url
and open by chrome, is fine
but it wrong on facebook, I have three marker in this map
but just last one stay,as below
(the last marker is test if facebook just keep last one)
here is my code
NSString *staticMap = [NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/staticmap?size=600x315&maptype=roadmap&markers=color:blue|label:S|%f,%f&markers=color:green|label:E|%f,%f&markers=color:red|label:T|25.2,122.5",dataManager.postCarpoolStartLat,dataManager.postCarpoolStartLng,dataManager.postCarpoolEndLat,dataManager.postCarpoolEndLng];
NSURL *staticMapURL = [[NSURL alloc]initWithString:[staticMap stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
NSLog(#"static url : %#",staticMapURL);
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"])
{
NSDictionary *params = #{
#"message":#"this is test",
#"caption":#"this is caption",
#"description":#"description",
#"link":#"www.google.com",
#"name":#"Name",
#"picture":staticMapURL,
#"type":#"mobile",
};
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"me/feed"
parameters:params
HTTPMethod:#"post"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error){
if (!error)
{
NSLog(#"post success");
}
}];
}
Is anyone know how to let facebook show the right map?
thanks in advance

iOS Facebook read and publish likes

I have seen this documentation, but it asks for object-id to get number of like, it seems pretty simple but I am wondering for some time, how to get/know object-id of my object/thing?
Edit:
I am using this code:
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"/{object-id}/likes"
parameters:params
HTTPMethod:#"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
// Handle the result
}];
What is {object-id} here ?
Finally I got my object-id in Object browser, I was able to create object there, object id was also present there.

How to extract Facebook posts information

I'm using this code to read the last post with location of all my facebook friends:
(FacebookFriend is an object I've created mySelf and contains also the friend's id and _facebookFriends contains all my facebook friends)
_postsWithLocationList = [[NSMutableArray alloc] init];
for (FacebookFriend *currentFriend in _facebookFriends) {
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
NSString *path = [NSString stringWithFormat:#"%#/posts?limit=1&with=location",currentFriend.id];
FBRequest *postsWithLocationRequest = [FBRequest requestWithGraphPath:path parameters:nil HTTPMethod:#"GET"];
[connection addRequest:postsWithLocationRequest completionHandler:^(FBRequestConnection *connection, NSDictionary *result, NSError *error) {
NSDictionary *postData = [result objectForKey:#"data"];
if (postData.count != 0) //some people don't have any post with position
{
// how to extract "place" object?
}
}];
[connection start];
}
and then I would like to store every location in my NSMutable array _postsWithLocationList.
Once I've extracted *postData I printed it's content and it looked like a dictionary (where "place" is a key) exactly as in the Facebook Graph API Explorer.
But when I printed
NSLog(#"%i", postData.count);
I saw that the length of "postData" was always 1, so I think that it's a single object that contains all the instances of the post. I looked at https://developers.facebook.com but I don't understand the type of this object and how to extract it's content.

Resources