Facebook Connect - publishUserAction template problem - facebook

Not sure if this is the right place to post this but I have tried other places with no luck.
I am getting the error: "The template data provided doesn't cover the entire token set needed to publish the story"
My template is: "{*actor*} just scored {*points*} points."
My code is:
NSMutableDictionary* feedStoryParams = [[[NSMutableDictionary alloc] init] autorelease];
[feedStoryParams setObject:<MyBundle ID> forKey:#"template_bundle_id"];
[feedStoryParams setObject:[NSString stringWithFormat:#"\"points\":\"42\""] forKey:#"template_data"];
[[FBRequest requestWithDelegate:self] call:#"Feed.publishUserAction" params:feedStoryParams];
This is after the user logs into facebook in my iphone app (and I checked to make sure the session ID is there).
I have tested also tested it by removing the "points" entry from the dictionary, and it then gives me the correct error saying that the {points} entry is missing and is required by the template "{*actor*} just scored {*points*} points." So I also know that the template bundle ID is correct.
If anyone has any ideas why this doesn't work, please let me know. I'm totally stuck :( Please help.
Thanks!!

I had the same problem. Putting everything in an explicit JSON hash fixed it. Try replacing
[feedStoryParams setObject:[NSString stringWithFormat:#"\"points\":\"42\""] forKey:#"template_data"];
with
[feedStoryParams setObject:[NSString stringWithFormat:#"{\"points\":\"42\"}"] forKey:#"template_data"];

Should 'actor' appear somewhere in the template_data?

Related

how can i query google places for country specific cuisine?

i am trying to accomplish country specific Cuisine places, means like mexican food, spanish food, Thai food, indian food, via google places API on an iPhone app.
How can i do that?? As i see supported types, there is only food, restaurant, etc in it. besides whenever i use this query..
NSString *url = [NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%#&type=restaurant&query=%#&sensor=true&key=%#", currentCentre.latitude, currentCentre.longitude, [NSString stringWithFormat:#"%i", currenDist], googleType, kGOOGLE_API_KEY];
i am getting few results only, whenever i try to add more types like food|restaurant|establishment like below query my app crashes.
NSString *url = [NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%#&type=food|restaurant|establishment&query=%#&sensor=true&key=%#", currentCentre.latitude, currentCentre.longitude, [NSString stringWithFormat:#"%i", currenDist], googleType, kGOOGLE_API_KEY];
As i told my app crashes with this error may be i am doing something wrong with url.
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
* First throw call stack: (0x13be022 0x200fcd6 0x1366a48 0x13669b9 0xbadfad 0x2dd2 0x13bfe42 0xaa09df 0x139294f 0x12f5b43 0x12f5424
0x12f4d84 0x12f4c9b 0x15d47d8 0x15d488a 0x17a626 0x236d 0x22d5)
terminate called throwing an exception(lldb)
Please can someone guide me with this?? i hope i cleared all my points.
Thanks & regards,
Malhaar
It appears you are trying to use the Places API Textsearch as you are using the query parameter. If this is correct make sure you are hitting the correct backend:
maps.googleapis.com/maps/api/place/textsearch/json
Also make sure you are using the correct parameter to specify types:
types=food|restaurant|establishment
I would recommend reading the documentation thoroughly and and performing a few test html requests through your browser to make sure you have the right request before plugging it into your application.
Although this is almost 7 months old, and I'm sure you've either solved it or given up on it by now, I have just had the same issue and it took some resolving. I thought I'd put the answer here to help anyone else with a similar error.
The problem I found was to do with the URL encoding not liking the | character.
The way around it I found was to:
// Create an NSString with the URL which includes the '|' characters.
NSString * urlString = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=51.189781,-114.488907&radius=6918&types=food|bar&keyword=&sensor=true&key=YOUR KEY HERE";
// Encode the URL
NSString* encodedURLString = [urlString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
// Covert to a NSURL
NSURL *googleRequestURL=[NSURL URLWithString:encodedURLString];
And then use the googleRequestURL as the URL.
Hopefully that will solve it for you!

NSString Memory Bug/Crash

I have UITextField of username and password, once the user hit the submit button I do
NSString* user_name;
NSString* pass_word;
UITextField * username;
UITextField * password;
NSString * url;
user_name=username.text;
pass_word=password.text;
url = [[NSString stringWithFormat:#"devices.json?user=%#&pswd=%#", user_name,pass_word];
However, when I try that, sometimes I got EXEC_BAD_ACCESS issue with url, I used the Zombie tool and nailed it %# is the one causing issue with url string. %# expecting a NSString of user_name, pass_word but somehow in the process, the user_name and pass_word got mutated and got some junk values, not NSString anymore.
I try to use [user_name retain]; [pass_word retain]; [url retain]; but didn't help. It keep having EXEC_BAD_ACCESS issue with %# parameter of the url.
secondly I able to output the user_name, pass_word, it sometimes got some values that doesn't make sense. I don't where they got those values. I didn't put those values in. I am making a http call. somehow the http returned values sneaked inside the pass_word, and user_name, I have no idea why it's doing that.
secondly I able to output the user_name, pass_word, it sometimes got some values that doesn't make sense.
this usually means that you assign not initialized variables... and it explains the crashes if you try to nslog the values. but it's not possible to find out what's wrong from the part of the code you have included in your answer.
try to log the contents of username and password. (the uitextfields) .. you should use better variable names.
From a comment:
I declare NSString *user_name, *pass_word in common.h file which many
files need to access that one.
Unless you've got a singleton class, every time you alloc/init a new Common object it's going to have trash values. Objective-C best practices recommend against this sort of design. For most data, it's fine to store in a plist or in NSUserDefaults, but for the username and password string, you should store it in the keychain. Even better, you should store your password as a hash if the server will accept it.
Then use a category on NSString (call it something like NSString+Authentication) that has methods to pull the data from the keychain as well as insert it into the keychain.
Try using the allocation as well and see if it helps:
url = [[NSString alloc] initWithFormat:#"devices.json?user=%#&pswd=%#", user_name,pass_word];

XMPPRoster example for iphone?

I have looked at the sample code and still not able to figure out some key functionality of the framework without more in depth documentation. Normally there are books about frameworks but it seems like with this framework, you're on your own until it picks up more mainstream usage.
How do I get the roster list? I see that XMPPRosterCoreDataStorage has an NSMutableSet of rosterPopulationSet. Is this the set of XMPPUserCoreDataStorageObjects, i.e., users, that make up a roster?
My way I'm guessing is a hack--get the presence of every user as it's announced, and stash it in an array. Those are the online buddies. Somehow get the entire roster list, and everyone who is not online, is offline.
I figure that there should be an array of XMPPUserCoreDataStorageObjects, i.e., 30 contacts, 30 entries in the XMPPUserCoreDataStorageObjects table?
How would I access this array and how would I tell if they are online or not?
For online status, am I supposed to query something else, b/c it's not encapsulated in XMPPUserCoreDataStorageObjects is it?
I suppose I could use the didReceivePresence or similar methods, but all in all, I want to use the framework and not fight against it.
Appreciate it!
Thanks
Use XMPPRoster extension with either XMPPRosterCoreDataStorage or XMPPRosterMemoryStorage
Take a look at following code. Please note that this is not complete code but should give you an idea.
XMPPRosterMemoryStorage *rosterstorage = [[XMPPRosterMemoryStorage alloc] init];
xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:rosterstorage];
[xmppRoster activate:xmppStream];
[xmppRoster fetchRoster];

Can't get XML element with colon in the name using TouchXML

I have the following code:
NSString *subtitle = [[[node elementsForName:#"subtitle"] objectAtIndex:0] stringValue];
NSString *duration = [[[node elementsForName:#"itunes:duration"] objectAtIndex:0] stringValue];
The first line works perfectly. The second line though won't work. I assume it has something to do with namespaces, but I'm pretty new to all of this so I would appreciate any guidance. Thank you!
It turns out that I can use the elementsForLocalName:URI: to read the element correctly. Now the problem is that since I am using the TouchXML library, it doesn't seem like that method has been mapped over to the CXMLElement structure (see here).
So the question now is: how can I convert a CXMLElement to an NSXMLElement so that I can use that method?
"itunes" is the namespace identifier. It doesn't actually have any significance on its own, it just links a URI with the element in question. It looks like you're using the iTunes RSS extensions, which live under the namespace http://www.itunes.com/dtds/podcast-1.0.dtd.
So, for namespaced elements, I think (I'm not familiar with Objective-C or NSXML :P) you want to use elementsForLocalName instead:
[node elementsForLocalName: #"duration" URI: #"http://www.itunes.com/dtds/podcast-1.0.dtd"]
For the answer to the second question, see comments below.

Has anyone used Buzz Andersen's Simple iPhone Keychain code?

You can find it here.
I'm trying to understand his sample code in order to write a simple program with that stores passwords into the keychain and retrieves them for login. Has anyone done this before? It would be most appreciated if I can see any examples you may have.
There's really no code to demonstrate, he lists both calls there.
Heres's an example, for what it is worth:
NSError *error;
[SFHFKeychainUtils storeUsername:#"fred" andPassword:#"mypassword123" forServiceName:#"myService" updateExisting:YES error:&error];
NSString *storedPassword = [SFHFKeychainUtils getPasswordForUsername:#"fred" andServiceName:#"myService" error:&error];
To other newbies that use this code as is and don't understand why it doesn't work. Notice that the ServiceName is different (First without capital - "myService" and second with capital: "MyService"), that's why it doesn't work. Make the ServiceName the same.