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.
}];
Related
I am trying to update the privacy parameter so that the live video my app starts is posted on the user's timeline with the privacy set to "ALL_FRIENDS". I have looked through the documentation and the code I have come up with does not work:
NSString* livePath = [#"/" stringByAppendingPathComponent:[token.userID stringByAppendingPathComponent:#"live_videos"]];
FBSDKProfile *profile = [FBSDKProfile currentProfile];
if(profile.userID){
livePath = [#"/" stringByAppendingPathComponent:[profile.userID stringByAppendingPathComponent:#"live_videos"]];
}
NSMutableDictionary* param = #{
}.mutableCopy;
[param setObject:#"Test Title" forKey:#"title"];
[param setObject:#"Test Description" forKey:#"description"];
[param setObject:#"privacy" forKey:#"{#\"value\": \"ALL_FRIENDS\"}"];
[[[FBSDKGraphRequest alloc] initWithGraphPath:livePath
parameters:param
tokenString:token.tokenString
version:#"v2.6"
HTTPMethod:#"POST"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { //More code here }
I figured it out using Facebook's graph explorer (https://developers.facebook.com/tools/explorer/?method=POST&path=118477909176601%2Flive_videos&version=v3.2&privacy=%7B%27value%27%20%3A%20%27ALL_FRIENDS%27%7D&classic=0). The code for setting the param to update the privacy settings is below.
[[[FBSDKGraphRequest alloc] initWithGraphPath:livePath
parameters:#{ #"privacy": #"{'value' : 'ALL_FRIENDS'}",}
tokenString:token.tokenString
version:#"v2.6"
HTTPMethod:#"POST"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
Hi I have recently started coding for iOS.I am trying to get videos from facebook using the following code.
-(void)facebookGetVideos:(UIViewController*)vc completionHandler:(void (^)(NSMutableArray*))completionBlock{
__block NSMutableArray * itemArray;
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"me/videos/uploaded"
parameters:#{#"fields":#"source,description,thumbnail,title"}
HTTPMethod:#"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
if(error!=nil){
NSLog(#"Error after fb dwnld %#",error);
[MBProgressHUD hideHUDForView:vc.view animated:true];
[self showAlert:#"Error" message:error.localizedDescription viewController:vc];
}else{
NSLog(#"Results %#",result);
itemArray = [[NSMutableArray alloc]init];
// [itemArray addObject:[result valueForKey:#"data"]];
itemArray =[result valueForKey:#"data"];
completionBlock(itemArray);
}
}];
}
The response I am getting from there is as below:-
{
data = (
{
id = 1845903302379295;
source = "https://video.xx.fbcdn.net/v/t43.1792-2/27475816_220074475216744_8742438766032977920_n.mp4?efg=eyJybHIiOjE1MDAsInJsYSI6MTAyNCwidmVuY29kZV90YWciOiJzdmVfaGQifQ%3D%3D&rl=1500&vabr=382&oh=d4c3f6028a979c5919fdd8e444e24179&oe=5A89882A";
},
{
id = 1814936632142629;
source = "https://video.xx.fbcdn.net/v/t42.14539-2/23925286_2650490725061654_2502749796398268416_n.mp4?efg=eyJybHIiOjU3NiwicmxhIjo1MTIsInZlbmNvZGVfdGFnIjoic2QifQ%3D%3D&rl=576&vabr=320&oh=2fde1aea6eff33d8139ccb8fe7a33fd4&oe=5A8980C0";
}
);
paging = {
cursors = {
after = MTgxNDkzNjYzMjE0MjYyOQZDZD;
before = MTg0NTkwMzMwMjM3OTI5NQZDZD;
};
};
}
I am trying to use this after before as parameters as below:-
-(void)afterValues:(NSString*)afterVal{
NSDictionary * parameters =#{#"fields":#"source",#"after": afterVal};
FBSDKGraphRequest *request1 = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"me/videos/uploaded"
parameters:parameters
HTTPMethod:#"GET"];
[request1 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
NSLog(#"after videos%#",result);
}];
}
And getting the following as response:-
after videos{
data = (
);
}
Can anyone please point out at my mistake.Any kind of help/suggestion or guidance in this directions would be highly appreciated.Thanks in advance!
Have you requested the manage_pages permission from the respective user through the login dialog? I think you see an empty result because of the missing permission.
I have written following code to post on facebook page but getting this error message: “(#200) Unpublished posts must be posted to a page as the page itself.“;
NSString *accesstoken = #"EAACEdEose0cBAAe49xNZBS5MqswXkRptXgLDRuZBZBPZCZCVl5rxW6Bt0jthaHXMACNTiUWePg9XkVTpttDNsLyWYBaEkQaUCm5vbSJQh8zGwkegAcQRjRggAJajunmMyg0jVIKZAZBzMjbZCKWUv1Tie1UzF8gJCpIxACIVgqx7SqKdPZBnIUaElk3meB7SYo6AZD";
NSString *pageId = [dic valueForKey:#"id"];
NSDictionary *dicPara=#{#"message": #"Hello",#"access_token":accesstoken,#"scheduled_publish_time": [NSNumber numberWithInt:timestamp],#"published": #"false"};
NSLog(#"%#",dicPara);
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:[NSString stringWithFormat:#"/%#/feed",pageId]
parameters:dicPara
HTTPMethod:#"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
// Insert your code here
if (error)
{
NSLog(#"%#",error);
}
else
{
[arrPostId addObject:[result valueForKey:#"id"]];
}
}];
Now I have searched for this error and found that you have to set accesstoken of the page instead of user's token. So how can I change user's access token to page accesstoken?
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
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.