app crashing while I try to tweet - iphone

I am using SA_OAuthTwitterController api for integrating twitter. While I try to post the tweet using
[_engine sendUpdate:tweetTextField.text]
my app crashes. I am getting the error:
Authenicated for (null).
Also My stack after crash shows me:OAMutableURL Request URL encoded string. what the problem ?

From the limited amount of information given it seems that no user has been authenticated. You may authenticate the user with a different instance of _engine which would be causing a crash.
and also may your URL not encoded with string here bellow some characters encode code define in bellow link after use this code in your URL if special characters are use...
http://www.w3schools.com/tags/ref_urlencode.asp
and also for encode the NSURL just use bellow code...
NSString* escapedUrlString =
[unescapedString stringByAddingPercentEscapesUsingEncoding:
NSASCIIStringEncoding];
hope,this help you...
:)

Related

iphone App crashing After FbRequest method

I have made an iPhone App which has a "loginwithFacebook" button , the login procedure is working fine . but App crashes after passing through the FBRequest method "- (void)request:(FBRequest *)request didLoad:(id)result " and "- (void)connectionDidFinishLoading:(NSURLConnection *)connection " .
I tried to put some break point in these methods. Then , I was amaized to see that App is working After some delay with that i made putting the break points.
Is it something related to loading the connection or Delay of the content loading from
Fbrequest method ???
please help me ..
[NSNull lowercaseString] which means your one string is null and you are trying to apply lowercaseString method to that string. keep a null check condition before this method call or you can check why this string is null.
It may be related to the access token of Facebook. because when u log in with Facebook, you will get one access token, and that token is used everywhere, so try to check the access token as its not nil. and this is just my assumption but will request you to keep your code where the crash happened. else post the crash reason from console.

Using retweeted_by API with MGTwitterEngine - keeps on returning error 404

I'm trying to add a method to MGTwitterEngine to use twitter's retweeted_by API ( http://dev.twitter.com/doc/get/statuses/:id/retweeted_by ).
Here is what I've added to MGTwitterEngine.m (all the OAuth stuff is done, the other methods inside the engine work fine)
-(NSString *)getUsersWhoRetweetedTweetWithID:(unsigned long)ID {
NSString *path = [NSString stringWithFormat:#"statuses/70482402362933249/retweeted_by.xml"];
return [self _sendRequestWithMethod:nil path:path queryParameters:nil body:nil
requestType:MGTwitterUsers
responseType:MGTwitterUsers];
}
Note: I've already included the .xml format and a status ID - just to ensure there's nothing wrong with the data I'm passing on. When I call [_engine getUsersWhoRetweetedTweetWithID:0]; from my app controller, error 404 is returned "The operation couldn't be completed. (HTTP error 404.)".
I've tried it with a parameters NSDictionary & tried changing the request & response types.
Currently, I don't make use of MGTwitterEngine to check who RTd a tweet, I just use a non OAuth'd method - however this will not return protected users who RTd a tweet.
Can anyone give me a point in the right direction - it's being driving me crazy for the past few days! I really appreciate any input :)
Take a look here.....
How to do a RETWEET on an iPhone twitter app (MGTwitterEngine)
MGTwitterEngine does not support re-tweet method yet .. you have to manually add the parse to MGTwitterEngine .h and .m then the call out would be [_engine sendRetweet:(unsigned Long)];
Now I am in the process of trying to determine how you call out the unsigned long...if any one else has an answer to that I would be happy to hear it myself.

Facebook oauth/access_token missing

Dunno if Im missing something but here goes. Im trying to get an access_token for my application so that it can go and look up events for certain public groups on facebook, without requiring a user to be logged in.
Im trying to get an access_token from
https://graph.facebook.com/oauth/access_token?client_secret=foobar&client_id=foobar&grant_type=client_credentials&format=json&sdk=ios
This returns a string: access_token=xxxx|ugtqdoWfvvo5_S-Fo2D7_I4rdbc
Thats nice and all, but its no json. Any insights on why the returned string is not json encoded ?
Note:
Im using the Facebook ios SDK function like so
[_facebook requestWithGraphPath:#"oauth/access_token" andParams:params andHttpMethod:#"POST" andDelegate:self];
This is a BUG: https://developers.facebook.com/bugs/325262010847554
Facebook's OAuth 2.0 implementation is clearly in violation of the spec: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-v2-25#section-5.1
I'm using Server-side Web App flow and have the same issue that you describe for the iOS SDK.
This is fixed as of v2.3 of the graph api. Specify the version by using endpoint https://graph.facebook.com/v2.4/oauth/access_token.
It's easy to accidentally land on the wrong version of the facebook API docs.
Here's a snippet to extract your access token and replace the pipe character with the proper escape...
NSURL *accessTokenURL = [NSURL URLWithString:#"https://graph.facebook.com/oauth/access_token?client_id=XXXXXXXXXXXXX&client_secret=XXXXXXXXXXXXXXXXXXX&grant_type=client_credentials"];
NSString *accessTokenResponse = [NSString stringWithContentsOfURL:accessTokenURL encoding:NSUTF8StringEncoding error:NULL];
if(accessTokenResponse != nil) {
NSMutableString *accessToken = [NSMutableString stringWithString:[accessTokenResponse substringFromIndex:13]];
[accessToken replaceOccurrencesOfString:#"|" withString:#"%7C" options:NSLiteralSearch range:NSMakeRange(0, [accessToken length])];
}
Follow up.
The way I understand the FB ios SDK is that your delegate function will receive an object such as NSArray or NSDictionnary to work with. Looking into the internals of the FB SDK classes it seems that all response are parsed using the SBJSON parser. If the response is not json than that will fail.
[_facebook requestWithGraphPath:#"261247595170" andDelegate:self];
returns nice json. No problems there.
[_facebook requestWithGraphPath:#"oauth/access_token" andParams:params andHttpMethod:#"POST" andDelegate:self];
String returned. SBJSON parser fails.
This seems to be an inconsistency in the FB graph service.
One could write a special function to handle this problem, but if FB decides to change the format of the string, then all IPhone App would stop working, and need to update. Not cool.
If you're using Facebook SDK, I believe that they return NSArray and NSDictionnary
I might be wrong, but try with an objectForKey:#"access_token"
Any insights on why the returned
string is not json encoded ?
Yeah, the access token isn't supposed to be JSON-encoded. And there's arguably little value in JSON-encoding a single string anyway.
Why are you expecting it to be so?
Seems I was misinformed about this. The spec states that application/json is to be used for the response body.

Tracking iPhone on Yahoo Web Analytics using ASIHTTPRequest

I'm trying to track an event in my app using Yahoo Web Analytics. The code I am using looks like
ASIHTTPRequest *yahooTrack = [ASIHTTPRequest requestWithURL:
[NSURL URLWithString:#"http://s.analytics.yahoo.com/p.pl?a=xxxxxxxxxxxxx&js=no&b=yyyyyyyyyyyy&cf6=zzzzzzzzzzz"]];
yahooTrack.didFinishSelector = #selector(statisticsFinished:);
yahooTrack.delegate = self;
[yahooTrack startAsynchronous];
Then the statisticsFinished looks like:
NSLog(#"Cookies: %#", request.requestCookies);
NSLog(#"Redircount: %d", [request redirectCount]);
NSLog(#"Responsecode %d %#\nMsg: %#", request.responseStatusCode,
request.responseStatusMessage, [request responseString]);
And all the information I get back looks correct. Cookies are set, redirectcount is 1 the first time (as it redirects to s.analytics.yahoo.com/itr.pl?.... a normal browser does). Then the redirectcount is 0 for subsequent request until the app is restarted and session cleared. The responseString returns GIF89a.
Even if the data looks correct, Yahoo still won't track. As soon as I call the tracking url directly in my browser it works as expected.
I realize Flurry is a better option, but I'm forced to use Yahoo in this case. Also, using a UIWebView probably would work, but I'm against putting in a webview just for tracking purposes.
Is there any difference in how ASIHTTPRequest and Safari would handle a call to a simple URL as this? Or do you see anything else that could explain why the tracking isn't working?
I finally found the problem. ASIHTTPRequest creates a user-agent based on your applications name, and requests from this user agent is ignored by Yahoo somehow (bug?). As stated in the documentation, you can override the user-agent as follows:
[request addRequestHeader:#"User-Agent" value:#"My-User-Agent-1.0"];
I used the user-agent string of Safari on iPhone, and it worked immediately! BTW; the same problem applies for Android, and the same fix works.

How to use iPhone Custom URL schemes

I've got an app that I want to be able to use Custom URL schemes for. I want users to be able to open Tweetie using the Custom URL protocol however I need to populate the tweet with dynamic website link which I get using currentItem.link.
I found this code which launches Tweetie and populates a message with static information:
NSString *shortened_url = #"http://your.url.com";
NSString *stringURL = [NSString stringWithFormat:#"tweetie://%#", shortened_url];
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
So using the above code how would I populate the message with currentItem.link information?
Thanks.
It depends entirely on the application on the receiving end. You have to find out how their protocol works, then you can use their protocol as it is designed.
Adding a http:// protocol URL to the end of a tweetie:// protocol URL is not the correct method, and searching for how the Tweetie URL protocol works would be suggested.
The Tweetie protocol is documented, but it's not clear how much of this still applies since the client was converted to the official Twitter one. I believe that the format you want is:
NSString *stringURL = [NSString stringWithFormat:#"tweetie://post?message=%#", shortened_url];
I have already tried this to get the account selection parameter to work. The basic method works, but account selection does not for me.