facebook post action url error - objective-c

Im working on posting to facebook on an ios app. I had it working fine but somehow it has stopped working. I have the users auth at this point and all thats fine it just keeps giving me this error when i try to post to facebook "the post's action links must be valid urls"
below is my code for the post
currentAPICall = kDialogFeedUser;
SBJSON *jsonWriter = [[SBJSON new] autorelease];
// The action links to be shown with the post in the feed
NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
#"someName",#"name",#"www.validurl.com",#"link", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
// Dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
shareInfo.facebookShareText, #"name",//name is heading with link to above
#"text text text", #"caption",// caption makes text grayed out
#"more wonderful text", #"description",// block text for the share
shareInfo.shareUrlShort, #"link",//actual link
shareInfo.facebookShareImage, #"picture",//url of picture to be displayed
actionLinksStr, #"actions",
nil];
//the post's action links must be valid urls
//make post to wall feed
[_facebook dialog:#"feed"
andParams:params
andDelegate:self];
the post works if i remove the actionLinksStr from the params as the error says that the link within it is not valid. This has been working for months but just stopped when i tried it today and i cant seem to get it back working again. Has anyone any idea why this error would suddenly start happening with no change to the actual sharing code? the url im passing into the action link is definately valid. any help would be much appreciated thanks
edit: just gonna flag this as a bug on facebooks dev site. see if i can get any feedback from there. still a mystery to me

Make sure you are using a valid URL. In your code example above, change www.validurl.com to a complete URL: http://www.validurl.com

Related

Why NSURLErrorDomain -1000 (bad URL) for specific NSURLs only?

I looked through all the relevant questions I could find (search: "NSURLErrorDomain -1000"), and couldn't find a solution. Maybe somebody eagle-eyed could help me.
I'm making calls from iOS 6 to the Instagram API (but the parts that work, did so already in iOS 5.1). I'm using Koolistov's NSURL+PathParameters.h as a helper, and my understanding is that it does indeed escape everything that is necessary in the URL.
Some preliminaries:
NSDictionary *parameters = nil;
NSURL *URL = [NSURL URLWithString:#"https://api.instagram.com/"];
parameters = [NSDictionary dictionaryWithObjectsAndKeys:
INSTAGRAM_CLIENT_ID, #"client_id", nil];
URL = [URL URLByReplacingPathWithPath:#"/v1/tags/awesome/media/recent"];
URL = [URL URLByAppendingParameters:parameters];
(INSTAGRAM_CLIENT_ID is a macro that contains my app's client ID.)
This URL works as expected.
However, the URL constructed as follows gives me NSURLErrorDomain code = -1000 consistently (on device and on both iPhone 5.1 and 6.0 simulators):
double latitude = 48.858844;
double longitude = 2.294351;
parameters = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithDouble:latitude], #"lat",
[NSNumber numberWithDouble:longitude], #"lng",
[NSNumber numberWithInt:2000], #"distance",
INSTAGRAM_CLIENT_ID, #"client_id",
nil];
URL = [URL URLByReplacingPathWithPath:#"/v1/media/search"];
URL = [URL URLByAppendingParameters:parameters];
I then create an NSURLRequest:
NSURLRequest *req = [NSURLRequest requestWithURL:URL];
If I print out the URL from the NSURLRequest, it seems quite OK:
https://api.instagram.com/v1/media/search?client_id=REDACTED&distance=2000&lat=48.858844&lng=2.294351
I'm using MyDownloader from Matt Neuburg's Programming iOS 5, Chapter 37. I create an instance of MyDownloaderand pass it the NSURLRequest:
MyDownloader *downloader = [[MyDownloader alloc] initWithRequest:req];
Accoding to RFC 3986, underscores or dots don't need to be escaped, I don't see anything else to be escaped, and NSURL+PathParameters.h should handle escaping anyway. So what is going on here? What am I missing?
To add to the weirdness, also this even simpler way of constructing the URL gives the same error:
parameters = [NSDictionary dictionaryWithObjectsAndKeys:
INSTAGRAM_CLIENT_ID, #"client_id", nil];
URL = [URL URLByReplacingPathWithPath:#"/v1/media/popular"];
It also looks OK:
https://api.instagram.com/v1/media/popular?client_id=REDACTED
All of these URLs work in the Instagram API console and directly in Safari. These API calls don't need OAuth authentication, just the client ID.
I would be greatful if somebody could point out what the problem is.
EDIT: encoded the lat and lng values with:
[[[NSNumber numberWithDouble:latitude] stringValue]
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
No change in URL or behavior. But when I replace the dots with literal %2E's, the path helper encodes the percent sign, resulting in %252E...
Solved. There was nothing wrong with the URLs shown above. The problem was with surrounding code. I'm answering my own question so that someone working with the Instagram API might benefit from the answer.
It turns out that the /v1/tags/tagname/media/recent endpoint of the API returns a pagination object in the JSON response, but the /v1/media/search and /v1/media/popular do not. From inside that object you can find the URL to the next batch of photos, in a value called next_url.
Because I hadn't read the documentation properly (and it was a little confusing in places), and because the different Instagram API endpoints work differently, my code expected to find the next_url value in all those cases. So the "bad URL" I was getting from NSURLConnection was referring to the second connection, and not the initial URL. Since I did not realize there is no pagination in the two other cases, I assumed that the problem must be in the initial URL.

Passing a Facebook Places id, from placesPicker in iOS... to postParams for a feed publish

This has been driving me bananas! I'm trying to get my app to publish a message to the users facebook feed, and a checkin to a facebook Place after selecting a local place from the placesPicker in iOS.
I've pretty much got everything working in testing, meaning when I just hand type string values for all the postParams for the NSMutableDictionary, it posts perfectly. ex:
self.postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"I am doing XYZ", #"message",
#"123456abc",#"tags",
#"123456xyz,#"place",
nil];
The above postParams work perfectly when published to feed, it displays the message, then checks in to the "place" id and says you are with the userid in "tags". The problem is that I am really getting the Place id from the Facebook SDK's placePicker. I've got the picker setup and working perfectly, but I can not figure out how to replace the hardcoded #"123456xyz" with the id from the picked Place.
this is currently what I have in there now:
self.postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"I am doing XYZ", #"message",
#"123456abc",#"tags",
self.selectedPlace.id,#"place",
nil];
self.selectedplace.id does successfully contain the id of the Place, when i print it with debug/NSLog in console, it is holding the value accurately. but when i try to publish this after picking a place, I get "error: domain = com.facebook.sdk, code = 5"
Here is how self.selectedPlace is defined & synthesized:
#property (strong, nonatomic) NSObject<FBGraphPlace> *selectedPlace;
...
#synthesize selectedPlace = _selectedPlace;
...
[placePicker presentModallyFromViewController:self
animated:YES
handler:^(FBViewController *sender, BOOL donePressed) {
if (donePressed) {
self.selectedPlace = placePicker.selection;
}
}];
So, to sum my question: How can I successfully get this Place id that is stored in self.selectedPlace.id into the postParams dictionary, so that it can be successfully interpreted & published to the user's feed?
Also, I should warn everyone upfront... I am self taught and still learning, and although I can look at the code, understand what it does, and write it... I'm afraid I'm not great with the terminology & discussing/understanding some of the language... lol so it would help me a great deal if you keep that in mind in any answers or comments :) Thanks, and I'm looking forward to breaking out of my stackoverflow newb shell and becoming more apart of the community here.
Figured it out... rather than setting the post params collectively with initWithObjectsAndKeys, like this:
self.postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
#"I am doing XYZ", #"message",
#"123456abc",#"tags",
self.selectedPlace.id,#"place",
nil];
Just create separate dictionaries for each param you are passing and set each one to the final postParams with setValue: forKey:
[fbPostParams setValue:self.selectedPlace.id forKey:#"place"];

iOS5 and Facebook SDK 3.01/Facebook feed

I'm going crazy. I've installed the Facebook SDK 3.01. I've added it to my frameworks. I've imported it into my view controller. I'm using the code from the Facebook developers' page, as follows:
UIImage *pic = [self createImage];
NSString *list = self.haiku_text.text;
NSString *kAppId=#"xxxxxxxxx0507";
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:kAppId, #"app_id",nil, #"link", pic, #"picture",#"Haiku", #"name",nil, #"caption",#"Maybe he'll love me if I give him a haiku....",#"description",nil];
[facebook dialog:#"feed"
andParams:params
andDelegate:self];
And no matter what I do I get a use of undeclared identifier 'facebook' error. This suggests to me that facebook needs to be an instantiation of some class or property--but I've been looking for what feels like millennia and I can't find out anywhere what that class or property is. What I've read on stackoverflow makes me think it used to have something to do with FBConnect, but that doesn't seem to exist in the new Facebook SDK.
Any thoughts that will help me keep at least a little of the hair I'm tearing out?

Cancel image upload to Facebook from iOS

I have an app that uploads an image to Facebook. this is the part of my code that does that:
[[self appDelegate] facebooking]; // checke that the user is loged in
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
labeledImage, #"source",
FB_IMG_POST_TITLE,#"message",
nil];
[ [[self appDelegate] getFacebookVar] requestWithGraphPath:[NSString stringWithFormat: #"/me/photos?access_token=%#", self.appDelegate.getFacebookVar.accessToken] andParams:params andHttpMethod:#"POST" andDelegate:self];
I want to
A) make the upload process a different thread.
B) Give the user the option to cancel the upload.
How would I do that?
Firstly, you are not using the facebook SDK correctly. You should not need to explicitly add the access_token. Please see the sample code for this.
You shouldn't need a different thread, the request will be handled asynchronously. What made you think you need to do this?
I'm not sure you can do B) by default. You could change the sdk source to give access to the NSURLConnection (which you can cancel).

Post to Friend's Wall with iOS Facebook SDK

Is it possible to use the iOS Facebook SDK's dialog method to post to the active user's friends' walls? That is, assuming the correct permissions have been granted?
Using the dialog method, with "feed" as the action, only seems to allow me to post to the user's stream, not to anyone elses. What am I missing?
[facebook dialog:"feed" andParams:... andDelegate:self]
The params only specify the content of the post; there doesn't seem to be any way to specify the profile I want to post to.
Just use the following code:
[facebook requestWithGraphPath:#"[IdOfFriend]/feed" andParams:... andHttpMethod:#"POST" andDelegate:self];
post on friends wall through graph path no more works
your feed action works.. have params like
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Checkout my APP_NAME", #"name",
#"Come visit my APP_NAME", #"caption",
[NSString stringWithFormat:#"I just joined APP_NAME Can you?"], #"description",
#"http://www.friendsmash.com/images/logo_large.jpg", #"picture",
#"FRIEND'S_FB_USER_ID", #"to",
// Add the link param for Deep Linking
[NSString stringWithFormat:#"https://YOUR_WEB_LINK.com/"], #"link",
nil];
Cheers...!