post google static map to facebook wall - ios

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

Related

How to use facebook pagination in ios

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.

schedule post on facebook page using facebooksdk

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?

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.
}];

how to get fb friends list using Facebook iOS sdk 4.2

I'm trying to find out all Facebook friends list by using the Facebook iOS sdk 4.2.
my code is
NSDictionary *param=[NSDictionary dictionaryWithObjectsAndKeys:#"picture.width(1000).height(1000),
name,
link",
#"fields",
nil];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:#"me/friends"
parameters:param
HTTPMethod:#"GET"];
[request startWithCompletionHandler : ^(FBSDKGraphRequestConnection
*connection,
id result,
NSError *error) {
NSLog(#"facebook friends :%#",result); // Handle the result
}];

ios facebook sdk get and display username

I have been working with the facebook sdk and parse and I am trying to retrieve a users facebook name but the documentation doesn't give me sufficient help and most tutorials on the net are out dated.
Can anyone tell how I can get a users name from the facebook sdk to display as a text label ? This would be greatly appreciated thanks.
You need to implement following FBLoginViewDelegate
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
{
NSLog(#"user is %# %#", [user objectForKey:#"email"], user.name);
}
You can retrieve it in this way:
FBRequest *request = [[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:#"me"];
[request startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary < FBGraphUser > *my,
NSError *error)
{
NSString *username = my[#"username"];
}
I finally figured it out, you have to request the current users profile information than set your label with a "key" which in this case is called "name"
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:#"me"
parameters:nil];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"fetched user:%#", result);
_usernameText.text = result[#"name"];
}];

Resources