iPhone FBConnect, dashboard.addnews - ios

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!!!

Related

Apigee user authentication, access_token, and cache login session in iOS

I'm new to Apigee and can't seem to wrap my head around it. I am familiar with implementing an iOS app that talks to a database via a webservice call. The call would involve passing back and forth JSON or variables though POST, GET, etc.
The user flow I envision is a lot like Facebook long term token storage. Here are the steps:
Type username and password to login.
The app will remember the access_token in the keychain.
The access_token will be used with any future requests such as updating profile. This way the user doesn't have re-login every time he/she is using the app.
Log out will clear all the token.
If the token is invalid or expired, the app will take the user back to login.
I've taken multiple routes and ended up getting stuck on all of them when it comes to Apigee.
ROUTE 1
I made a call to logInUser and receive access_token in return.
[self.apigeeDataClient logInUser:username password:password];
All this is good until I want to update user's email address using the code below.
NSMutableDictionary *requestDict = [NSMutableDictionary dictionary];
[requestDict setObject:email forKey:kDataEmail];
NSString *url = [NSString stringWithFormat:#"%#/%#/%#/users/%#?access_token=%#", BASE_URL, UG_ORG_NAME, APP_NAME, [userData objectForKey:kDataUUID], self.accessToken];
NSString *op = #"PUT";
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:[NSDictionary dictionaryWithDictionary:requestDict]
options:0
error:&error];
[self.apigeeDataClient apiRequest:url operation:op data:[NSString stringWithUTF8String:[jsonData bytes]]];
It seems that every other time it's giving me "No content to map to Object due to end of input" error. I checked out this thread but have no luck. I made sure the JSON object is not null. I tried changing the operation from PUT to POST and GET. None of which update the email address in the database.
ROUTE 2
Instead of using apiRequest, I switched to updateEntity.
NSMutableDictionary *requestDict = [NSMutableDictionary dictionary];
[requestDict setObject:email forKey:kDataEmail];
[requestDict setObject:kDataUsers forKey:kDataType];
[requestDict setObject:self.accessToken forKey:kDataAccessToken];
NSString *entityID = [userData objectForKey:kDataUUID];
[self.apigeeDataClient updateEntity:entityID entity:requestDict];
It looks promising except I started getting "Subject does not have permission" like the issue described in this thread. I tried calling assignPermissions like mentioned in Apigee document but that didn't solve the problem. I even provide access_token with the call, even though I shouldn't have to.
In the attempt to avoid calling login also tried calling storeOAuth2TokensInKeychain and retrieveStoredOAuth2TokensFromKeychain mentioned here. That didn't work either.
The only thing way to resolve this error is by calling logInUser before making a call to updateEntity. This means the user will have to login every time he/she wants to use the app. I know I can store username/password in the keychain. But before I do that I'm wondering if there's better solution out there.
I know it's a long post. So thank you for reading this far. Any pointers are greatly appreciated.

Facebook's "Messaging an Open Graph message" functionality keeps on returning to my app

I'm trying out Facebook's new Messaging an Open Graph message, which means one can now send open graph stories to friends via the Facebook Messenger app.
In my case, I am building an app where people create a playlist and can then invite others to contribute songs to that said playlists. Therefore, an interesting path to take is being able to post an open graph message via Facebook Messenger to one's friends.
I have set up a Create action, a Playlist object and a Create a Playlist story.
The code I use in the iOS app is very close to the one provided as an example by Facebook:
Creating the playlist object:
NSMutableDictionary<FBGraphObject> *object =
[FBGraphObject openGraphObjectForPostWithType:#"vibe-social-music:playlist"
title:#"Sample Playlist"
image:#"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
url:#"http://samples.ogp.me/616101581814728"
description:#""];
Creating the action:
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[#"playlist"] = object;
Creating the params:
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc]
initWithAction:action
actionType:#"create"
previewPropertyName:#"playlist"];
Calling the 'present message' dialog within the messenger app:
[FBDialogs
presentMessageDialogWithOpenGraphActionParams:params
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if (error) {
//TODO: Handle errors
NSLog(#"error: %#", error);
} else {
NSLog(#"results: %#", results);
}
}];
As I explained before, the Facebook messenger app opens, but quickly returns back to my application.
I have the Facebook credentials well setup in my Info.plist file.
The one thing is that the action is not yet validated by Facebook. Could that be an issue?
Otherwise, I'm at a loss as to why it won't show an Open Graph story in the Messenger app, and why it always goes back to my application.
Any help would be greatly appreciated, thanks!
Can you confirm you configured a custom story in the Open Graph section of your app settings (and not just the action and object types)?
Also, it looks like the action type is missing your app namespace in the params construction: i.e.,
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc]
initWithAction:action
actionType:#"vibe-social-music:create"
previewPropertyName:#"playlist"];

"Could not generate preview text" error when creating object with Open Graph action

I'm using the iOS SDK with the native dialog to try to post an object and action.
When I call presentShareDialogWithOpenGraphAction, the Facebook app opens, briefly shows the dialog with my post in it, and then returns to my app with the error:
Could not generate preview text
My code looks like this:
NSDictionary* object = #{
#"fbsdk:create_object": #YES,
#"type": #"appsterbator.app_idea",
#"title": #"test",
#"url": #"http://test.com",
};
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:object
forKey:#"app_idea"];
[FBDialogs presentShareDialogWithOpenGraphAction:action actionType:#"app_idea.create"
previewPropertyName:#"app_idea"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
NSLog(#"%#", error);
}];
Also, is it possible post an Open Graph object that doesn't actually have a URL?
I had the same symptoms, but a different fix. Facebook SDK 3.5.* since the Share Dialog came out of beta.
I had a custom Object Graph story: Solve -> Puzzle. This was my first time working with OG, so this might seem obvious to someone more familiar with it, but it stalled me for long enough that I wanted to share.
I ran through the Share Dialog examples on the developer site, but the Open Graph related sharing would not work via simple copy paste. I figured because the OG objects were tied to the App ID and URL host etc. I setup my web host so that I could serve OG data for my objects, and configured my app to allow that host etc..
So I set about adapting the sample code to use the parameters present in the "opengraph / stories -> Get Code" popover. Setting the platform to iOS SDK, I got the following for Create Action:
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[#"puzzle"] = #"http://samples.ogp.me/463417983744195";
[FBRequestConnection startForPostWithGraphPath:#"me/shapeshuffle:solve"
graphObject:action
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
// handle the result
}];
I swapped my story and app specific values into the sample code, leading to the the error and symptoms described in the question.
I spent longer than I care to admit fiddling with the server hosting my OG object, FB App settings, different ways of popping the share dialog etc.
The root of the problem was that on popping the dialog, FB was unable to match the action and object with the configuration in my app - hence the slightly vague error code relating to generating the preview text. FB wasn't finding the action because "me/shapeshuffle:solve" (the action string in the "Get Code" tool) doesn't resolve. If I understood all the different options available to me in the Get Code tool, I might have avoided this, but remember, all I wanted was to pop a share dialog. Seemed simple.
I worked with the Graph API explorer via this useful tutorial, and wound up with the following mapping from the strings I got from the FB tool to what actually worked:
Action:
me/shapeshuffle:solve => shapeshuffle:solve
Lots of pain for 3 little characters. Here is what my finished code looks like:
NSString *objectUrl = [NSString stringWithFormat:#"%#puzzleId=%d", #"http://myhost.com/puzzle/object?", puzzleId];
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:objectUrl forKey:#"puzzle"];
[action setObject:timeString forKey:#"time"];
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:#"shapeshuffle:solve"
previewPropertyName:#"puzzle"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
Had the same issue. Make sure the App Domains in Basic Info contains the oAuth domain. The odd thing I found is that in order to add this you need to enable this can only be added if you enable Page Tab or Mobile Web or one of the other options.
I think i may know the reason that (#"url": #"http://test.com")->this may use the facebook app developer center offer.
click Open Graph
click Stories
then you will see your custom story on right side
click Get Code,then you will get the URL you need!
and (#"type": #"appsterbator.app_idea")->this may need use like this->(your_app_namespace:action_type)
Good luck!
To problem with: "Could not generate preview text" come from attempts to share the same content several times.
Try to change content that you share each time you check the functionality of open graph.
A condition that causes this which has not been described yet is case sensitivity of the action and property name, which must be lowercase. To illustrate note the 'must_be_lowercase' in the following:
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:#"http://link/" forKey:#"**must_be_lowercase**"];
[FBDialogs presentShareDialogWithOpenGraphAction:action
actionType:#"xxxx"
previewPropertyName:#"**must_be_lowercase**"
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
This is a lovely generic error message! Another possible cause I've encountered is the size of the OpenGraph image being posted.
Although Facebook documentation states images must be 200x200px to 1500x1500px, my initial attempts with a 350x350px image failed with the “Could not generate preview text” error. The same image at 600x600px on the other hand works perfectly.
-James

iOS Facebook SDK - Posting A UIImage To User's Wall

Ok so there is a lot of threads on this, but nothing seems to work for me.
My app allows users to post a photo (which is a UIImage created by a screenshot of the App) to facebook.
However, I can currently only post the photo by using:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:[[appDelegate facebook] accessToken], #"access_token",nil];
[params setObject:#"Caption" forKey:#"name"];
[params setObject:[self captureScreen] forKey:#"source"];
if([[appDelegate facebook] requestWithGraphPath:#"me/photos" andParams: params andHttpMethod: #"POST" andDelegate:(id)self]){
[self.view addSubview:[Memos showMemo:facebookMemo]];//Show success alert
}
This works fine, but doesn't use any sort of FB Dialog.
I really want to use the dialog so users can feel like it is more "facebook official" and allow them to preview/confirm the post.
Is there any SIMPLE way to go about doing this?
This is the closest I have gotten: Post photo on user's wall using Facebook iOS SDK, but I have issues with these lines:
currentAPICall = kAPIGraphUserPhotosPost;
As xcode doesnt recognize any of the kAPI... objects...
Suggestions?

Can't get the Facebook publish_action permission on iOS

I've spent hours on this and can't get it to work. Basically I just want a button in my app that will 'Like' itself on Facebook.
I've created the app on dev Facebook and have an associated App Page.
In my code I request these permissions:
_permissions = [NSArray arrayWithObjects:#"publish_stream", #"publish_actions", #"user_birthday", nil];
I can retrieve a profile picture fine, but when I try to 'Like' using this code:
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
_facebook.accessToken, #"access_token",
nil];
[_facebook requestWithGraphPath:#"329756493773381/og.likes" andParams:params andHttpMethod:#"POST" andDelegate:self];
I get this error response:
(facebookErrDomain error 10000.)" UserInfo=0x20090590 {error={
code = 200;
message = "(#200) Requires extended permission: publish_actions";
type = OAuthException;
}}
When logging in on the app, Facebook asks me for permission to see my birthday, and tell's me it will Post on my behalf but it seems to not get the publish_actions permission.
Is there something i'm missing that I need to do?
I see Temple Run has a Facebook Like button and offers bonus coins for pressing it. This is what I wish to achieve.
EDIT -------
I've changed my permissions to just #"publish_actions", #"user_birthday" and now the auth dialogue says
"This app may post on your behalf, including objects you liked and
more"
which seems to be the publish_actions permission, however I was still getting the error
message = "(#200) Requires extended permission: publish_actions";
I've changed this line:
[_facebook requestWithGraphPath:#"329756493773381/og.likes" andParams:params andHttpMethod:#"POST" andDelegate:selrf];
to this:
[_facebook requestWithGraphPath:#"329756493773381/og.likes" andDelegate:self];
and I do now get a response back, although it doesn't post a 'like'
This is the result response:
{
data = (
);
paging = {
next = "https://graph.facebook.com/329756493773381/og.likes?sdk=ios&sdk_version=2&access_token=BAAGeAp3ZBGwoBAPICjlgB5zK0YECyP8yElf8hJoMrx8Qs4vjeZAK5PlXFAVbGM1JyXHE0wZBvU0aBeCzCUTZBejQgoJ44CAIQsrG64TfrHdxjMqWD&format=json&offset=25&limit=25";
};
}
Any idea what to try next?
EDIT 2 ---------------
I'm making progress with this.
I've added the users id to the graph request like this
NSString *graphPath = [NSString stringWithFormat:#"%#/og.likes",facebookID];
and used these parameters
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"AAAGeAp3ZBGwoBABvKjsPZAoQQNG9cDPJI2v2TI8acyyPSNtm9ZBkfydHqVZAjSKWSbLuvFwxyxSrCts7kFZCnh7Y6f5PFNlWb6smF8XF33wlRZBgfLyhT1", #"access_token",
#"http://samples.ogp.me/329756493773381", #"object",
nil];
and now I get a like showing up on my timeline :-)
I was using the access-token supplied by the Facebook login, but it seems the one supplied by the graph object is different.
Now, the like that i'm seeing has this pattern:
Darren likes object on MyAPP
Is it even possible to have it as
Darren likes MyAPP
with it linking to the app Facebook page?
Thanks
Check if you have done the steps below:
https://developers.facebook.com/docs/opengraph/tutorial/
"Note: The user-prompt for this permission will be displayed in the first screen of the Enhanced Auth Dialog and cannot be revoked as part of the authentication flow." - link
Try this if you havent already:
Auth Dialog -> Configure how Facebook refers users to your app - > Add publish_actions permissions.
https://developers.facebook.com/docs/opengraph/authentication/
"To enable the new Auth Dialog, go to the App Dashboard, and enable the Enhanced Auth Dialog setting in the Advanced section of your app." -link
Hope this helps!
This seems to be the same problem I was having on this SO question:
Facebook iOS SDK 3.0, implement like action on a url?
But if you want to like you facebook page in the app, there is no way to do that in Objective C. Only with the javascript Like button which you can generate here:
https://developers.facebook.com/docs/reference/plugins/like/
The way Temple Run does it is to display the Like button in a web-view, so their like button is actually on their server, this is perhaps an ugly-hack but will work for liking a page.

Resources