Pre-Fill Dialog box using FBConnect? - ios

A few months ago I used to be able to pre-fill the dialog box with my own text so the user would only have to click share to share that text but it seems that Facebook has started to ignore that parameter like they say in this post: https://developers.facebook.com/blog/post/510/
So is there any other way around it so I can pre-fill a message that the user can easily share?
Thanks!
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[super webViewDidFinishLoad:webView];
if (defaultStatus)
{
// Set the pre-filled status message
[_webView stringByEvaluatingJavaScriptFromString:
[NSString stringWithFormat:#"document.getElementsByName('feedform_user_message')[0].value = decodeURIComponent('%#')",
[SHKEncode(defaultStatus) stringByReplacingOccurrencesOfString:#"'" withString:#"\\'"]
]
];
// Make the text field bigger
[_webView stringByEvaluatingJavaScriptFromString:#"document.getElementsByName('feedform_user_message')[0].style.height='100px'"];
}
}

afaik it is not possible anymore to pre-fill the message box with the javascript api, which is a good thing. after all it is against the platform policies:
https://developers.facebook.com/docs/guides/policy/application_integration_points/
but: it should still be possible with the php api/sdk. you just have to allow the user to edit the message before you send it, with a textarea or input field. just make a post to /me/feed with the message parameter.

Related

Best way to check if sharing via SLComposeViewController is successful with a limited (or no) Internet connection

Apple's documentation is clear on using SLComposeViewController to provide sharing capabilites with other social networks such as Twitter and Facebook.
Typical code will use isAvailableForServiceType to verify if a particular service is available and then add a completion handler to the view controller where an SLComposeViewControllerResult can be checked for either SLComposeViewControllerResultCancelled or SLComposeViewControllerResultDone, which check if the user tapped on the 'Post' button or on the 'Cancel' button after the sharing view has been displayed.
The issue here is that if you use SLComposeViewControllerResultDone to validate that the user made the request, you don't actually check if it was successful such as when the user has limited or no connectivity.
I have tried with one of my apps to test this and have noticed that the SLComposeViewControllerResultDone constant is still valid even if airplane mode is turned on such that a request is not possible. What this means is that the user fills out the sharing view fields and taps on 'Post' and my success code executes even though I should really be checking to make sure that the post was indeed successful.
Currently, I figure that the best option is to check for an Internet connection using the standard Reachability options (as recommended here) and disable the sharing button if a connection is not available, but I'm not sure if this is the best solution as it doesn't account for a limited connection where the user can tap on 'Post' but the actual request is unsuccessful.
My question is what is the best method of detecting if a sharing request has successfully completed?
then you need to make sure that you do not write below line in didSelectPost
[self.extensionContext completeRequestReturningItems:nil completionHandler:nil];
and once you get success or fail based on that in the your request handler you can write above line, so your didSelectPost should be like :
- (void)didSelectPost {
NSExtensionItem *inputItem = self.extensionContext.inputItems.firstObject;
NSItemProvider *attachment = inputItem.attachments.firstObject;
if ([attachment hasItemConformingToTypeIdentifier:#"public.url"])
{
//NSString *strLink = [attachement loadItemForTypeIdentifier:#"public.url" options:nil completionHandler:nil];
[attachment loadItemForTypeIdentifier: #"public.url"
options: nil
// make your request here
}];
}
}

Share facebook without being able to edit text

I'm creating an game where I have a share button. In this share button I would like to share text and a link. It is important that the user can't edit the text since they would be able to change the score. What is the best solution for this? I've searched, but in most guides, you're able to change the text as a user.
What's the solution?
The short answer is that you're not supposed to post something on a user's behalf without giving them the option of editing the comment/status. You can do it with an API call (rather than a share sheet), but this should only be used to post content that the user entered elsewhere in the app.
// NOTE: pre-filling fields associated with Facebook posts,
// unless the user manually generated the content earlier in the workflow of your app,
// can be against the Platform policies: https://developers.facebook.com/policy
[FBRequestConnection startForPostStatusUpdate:#"User-generated status update."
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Status update posted successfully to Facebook
NSLog(#"result: %#", result);
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"%#", error.description);
}
}];
This is from Facebook's "Sharing in iOS" documentation
Another option (though possibly also against the rules) is to create an image from the text and let the user share the image. Before doing this, however, put yourself in the user's shoes - do you really need to post something like that?

Custom Login Instagram API iOS

I'm developing an application for iOS with the authentication, using Instagram API.
My code for authentication works good:
NSString *fullURL = [NSString stringWithFormat:#"https://instagram.com/oauth/authorize/?client_id=%#&redirect_uri=%#&response_type=code",KCLIENTID,kREDIRECTURI];
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
instagramConnectWebView = [[UIWebView alloc] initWithFrame:self.view.bounds];
instagramConnectWebView.delegate = self;
[instagramConnectWebView loadRequest:request];
When the request is sent, my webView shows the standard Instagram login interface, where user has to insert username and password to login. If login succeed, app is redirected to my redirection-url, where i get the code and the token of this user.
My question is really simple, is there a way to customize standard interface of Instagram login? I'd like to insert in my app two simple UITextField (One for username and one for the password) and when user clicks on my UIButton login, application should send (POST or GET?) username and password to Instagram, and return response (Login success or not).
I hope i explained myself.
Thanks.
You can make this by using javascript. by loading a web view in background :
You need to access the text field of that web view and pass value of your custom UItextfields and after that you can call webView's "Submit" button's Onclick event.
NSString *javaScript = #"document.getElementById('id_username').value = 'tfusername'";
NSString *javaScript2 = #"document.getElementById('id_password').value = 'tfpassword'";
to evaluate each script you can call: [webView stringByEvaluatingJavaScriptFromString:javaScript];
You can also call script to press login button. This same thing work for me. May be this will help you.
I have created a wrapper for Instagram API for iOS. Take a look at this link . This will also give an idea of what you need to do.

Facebook ios SDK - How to handle feed dialog callback?

I use the following code found on Facebook developer site to do a wall post:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"http://developers.facebook.com/docs/reference/dialogs/", #"link",
#"http://fbrell.com/f8.jpg", #"picture",
#"Facebook Dialogs", #"name",
#"Reference Documentation", #"caption",
#"Dialogs provide a simple, consistent interface for apps to interact with users.", #"description", nil];
[_facebook dialog:#"feed" andParams:params andDelegate:self];
This shows a popup letting the user write his message and press publish or cancel.
Is there any way to know if the post has been successfully pusblished or not (cancellation or connection problem)?
Many thanks!
Try using specifying a delegate other than self to be able to capture the response of the dialog.
See: http://developers.facebook.com/docs/reference/iossdk/dialog/
You should call this dialog if the method you are calling requires
parameters to set up the dialog. You should set up your delegate to
handle the scenarios where the dialog succeeds, is cancelled by the
user, as well as any error scenarios.
As for the delegate: http://developers.facebook.com/docs/reference/iossdk/FBRequestDelegate/ I would assume it would be the request:didReceiveResponse: delegate.
EDIT
with additional feedback, your answer lies in the dialogDidComplete delegate listed on the link I gave in my original response.
I think you can do it by using - (void)dialogDidComplete:(FBDialog *)dialog; method of FBDialogDelegate.
+1 for Hlung and DMCS for their help but it looks like the feed dialog is getting more and more deprecated, and handling proper callbacks is fiddly (impossible?).
Plus the FB doc isn't up-to-date.
So I ended up using a (void)requestWithGraphPath instead of (void)dialog which requires an extra permission to post on user's wall but works better with the 2 following callbacks:
- (void)request:(FBRequest *)request didLoad:(id)result
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error
Somewhat related to your question - I was trying to figure out which dialog had completed.
You can detect the parameters of the dialog, and check which one it is. I have this issue, as I send various dialogs, and want to know on the other end which one was a success or not.
- (void)dialogDidComplete:(FBDialog *)dialog {
// the song feed return
NSLog(#"params; %#",dialog.params);
if([[dialog.params objectFOrKey:#"ref"] isEqualtoString:#"songfeed"]){
// do stuff on return from this dialog
}
}

iPhone FBConnect, dashboard.addnews

How to add news via FBConnect?
I have the following code:
NSString *newsBody = #"[{\"message\": \"News message\" }]";
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObject:newsBody forKey:#"news"];
[[FBRequest requestWithDelegate:self] call:#"facebook.dashboard.addnews" params:params dataParam:nil];
After I sent the request I received the success responce. But I can't see the new news in the facebook account.
Also, I tried to add full info into news parameter (http://wiki.developers.facebook.com/index.php/Dashboard.addNews):
NSString *newsBody = #"[{\"message\": \"News message\",\"action_link\": {\"text\": \"link text\",
\"href\": \"http: //google.com\"} }]";
But this request returns error.
Any ideas?
I found the answer. The FBStreamDialog should be used to publish the news. It means that the custom interface cannot be used for this purposes. :(
Also, just wanted to say that FBConnect it's a one big mess!! Currently fighting with the bug when after clicking Cancel button in the FB dialog the dialog firing the event dialogDidSucceed but not dialogDidCancel. Such a big mess!!!

Resources