How to get my last TWEET into an NSString in my iPhone app? - iphone

There are a bunch of tutorials online about how to use xmlparsers or what not to bring an entire twitter feed into a UITableView. Thats not what I need. I only want ONE tweet. The most recent twitter update.
So, would some of you geniuses please show me in detail how to get my last (most recent) TWEET into an NSString in my iPhone app?

In short: exactly the same as all those tutorials that you've read except you pass the count parameter to the statuses/user_timeline REST method.

Ohh, this is complicated, not so easy, I show you the steps:
Make the request to the api (synchronous or asynchonous)
Handle the Authentication Challenge for authenticated request
Get the data, call the parse method of the parser
Handle the delegation methods of the nsxmlparser
Manually handle the DidStartElement, DidFoundCharacters, DidEndElement to get the first status you want, assign the string value to a variable when it founds the characters.
That's all you need to do ;)
Good luck.

Related

How to get live video id from YouTube channel

YouTube API eventType=live not working, does anyone have an idea why?
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCmyKnNRH0wH-r8I-ceP-dsg&eventType=live&type=video&key=
Without eventType was working fine (but not now):
https://www.youtube.com/embed/live_stream?channel=UCmyKnNRH0wH-r8I-ceP-dsg&autoplay=1
Looks like YouTube changed something in API, search.list really not returning live broadcast since end of last week.
If you have user's access token you can use https://www.googleapis.com/youtube/v3/liveBroadcasts?part=snippet&broadcastStatus=active&broadcastType=all
endpoint to retrieve if any broadcast is live.
If you do not have user's access token, you can try this answer
but i didn't check it if it is working
Anyway this question looks like to be a duplicate of this question
Right now the YouTube API is not working, specifically for retrieving live streams of a specific channelId. In other words if you are setting channelId in the API call, you will get 0 results.
If you're using an API key rather than OAuth (not sure if OAuth works) the only work around at the moment is to use the API to search for a specific title. Here is my query URL below.
https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&type=video&maxResults=20&order=date&q=My+Uniquely+Titled+Livestream&key=[apiKey]
The results returned by the API will be from all of YouTube. (Note: the rest is done serverside) Put the results into an array and discard any that don't match your channelId. Then check the titles in an array and only get the video ID of the one that matches your desired title. That is the basic logic and it is sort of a rigid work around that won't work for most. But at least it will get you what you need until Google fixes the API.

POST request from iPhone to Django

I'm trying to send a POST request from iPhone to Django, but for some reason I can't. The request is sent, but the server doesn't receive it properly.
What is the regular expression that accepts POST? In my case, I use this one: /messages/a/s=person1&r=person2&c=hello/.
How do I retrieve the POST arguments in the Django view? request.POST['s'] should work?
Thanks.
POST parameters are not part of the URL, so your regex should simply detail the main part of the url you want to receive it on. To take your example, change it to /messages/a/. Then, in your "messages" app, have a view/function called a: that one will be reached on receiving any POST (or GET, which you're currently (almost) depicting in your url) to that location.
The arguments can then indeed be retrieved using request.POST['keyname']. To make things more convenient, supply a default value when getting the data so you need less error checking: request.POST.get('keyname', None). This will get the value of keyname when available, or None otherwise.
The posting itself... depends on more code then you're currently showing. Can't say anything about that with your current question.
That URL you've pasted in will pass the data through the request.GET dictionary. If you want to change your iPhone app to POST data, you'll have to share your code.

iPhone facebook integration

I am using Graph API in my application. I am fetching user's facebook wall feeds using graph API also getting details of particular post i.e (Like count,Comments etc).
but i want to allow user to Like and Comment any post from the application itself.
what is the request format for that?
Please help me or give any pointers.
Regards,
Sanket
You would be well served to check out the Publishing section of the documentation. It provides information such as this.
One example is liking, which is defined as:
Method: /OBJECT_ID/likes
Description: Like the given object (if it has a /likes connection)
Arguments: none
Basically, just initiate a Graph API call to something like:
[facebookObject requestWithGraphPath:#"98423808305/likes" andDelegate:self];
That will "like" a picture from Coca-Cola (ID taken from the documentation).
Edit 1
According to the documentation:
Most write operations require extended permissions for the active user. See the authentication guide for details on how you can request extended permissions from the user during the authentication step.
Are you sure you have enough privileges? Unfortunately the documentation is very unclear as to whether it serves the dual purpose of liking the object and returning the likes already on that object.
Edit 2
I did some more research into what could be causing this and came across this question and answer that indicated that the code I posted above using requestWithGraphPath:: should work. However, it does not due to a bug on Facebook's Bug Tracker.
Unfortunately, it looks like there is no way to "like" an object via the Graph API, which seems very strange to me. Perhaps it is possible with the legacy REST API instead of the Graph API?
Edit 3
Well, it looks like your best bet is the stream.addLike method of the legacy REST API which you can still call using the Facebook iOS SDK. You should be able to use the stream.addLike method to "like" something in the "stream". Unfortunately, it doesn't appear to support photos, videos, etc. Only posts and comments.
Finally i found the solution for LIKE option
We should use following method for like option.
-(void) requestWithGraphPath:(NSString *)graphPath
andParams:(NSMutableDictionary *)params
andHttpMethod:(NSString *)httpMethod
andDelegate:(id <FBRequestDelegate>)delegate
graphPath = /OBJECT_ID/likes
Paramas = dictionary with comment ,for like option use empty dictionary
HttpMethod should be POST
you should get response = true if the LIKE request is successful.

Twitter API : Decode string returned by getFollowerIDsFor from Twitter (MGTwitterEngine for Obj-C)

New Question
Thank you for your reply Arcain. I guess question got mis-represented. I apologize for that.
My interpretation was like getFollowerIDsFor method as name suggests should be getting list of follower IDs, but it is not so.
My actual question is, how to use MGTwitterEngine API to get list of follower/following persons from Twitter. Though I went through documentation was not able to find out the same.
Regards,
Jennis
Previous Question
We can get list of Follower using getFollowerIDsFor through MGTwitterEngine object. It always returns some string which is not understandable for me i.e. how to decode or something like that ?
let say resultant string is "025815FA-BAF6-49E6-96B4-86F2D4C8C6CA"
how to understand what is there in this string ? can anyone highlight on this please ?
Help would be appreciated.
Regards,
Jennis
That value is a unique identifier and doesn't really mean anything. I'm not familiar with Cocoa, but when I looked around I found the following in the README file for MGTwitterEngine, and it seems relevant to what you're asking:
A note about the data returned from Twitter
Each Twitter API method returns an NSString which is a unique
identifier for that connection.
Those identifiers are passed to all
the delegate methods, so you can
keep track of what's happening.
Whenever a request is successful, you will receive a call to your
implementation of requestSucceeded: so
you'll know that everything went OK.
For most of the API methods, you will
then receive a call to the appropriate
method for the type of data you
requested (statusesReceived:... or
directMessagesReceived:... or
userInfoReceived:...). The values sent
to these methods are all NSArrays
containing an NSDictionary for each
status or user or direct message, with
sub-dictionaries if necessary (for
example, the timeline methods usually
return statuses, each of which has a
sub-dictionary giving information
about the user who posted that
status).
Just try calling some of the methods and use NSLog() to see what data you
get back; you should find the format
very easy to integrate into your
applications.
Sometimes, of course, requests will fail - that's just how life is. In the
unlikely event that the initial
connection for a request can't be
made, you will simply get nil back
instead of a connection identifier,
and then receive no further calls
relating to that request. If you get
nil back instead of an NSString, the
connection has failed entirely. That's
a good time to check that the computer
is connected to the internet, and so
on.
It's far more common however that the connection itself will go ahead just
fine, but there will be an error on
Twitter's side, either due to
technical difficulties, or because
there was something wrong with your
request (e.g. you entered the wrong
username and password, or you tried to
get info on a user that doesn't exist,
or some such thing). The specific
error conditions are mostly documented
in the Twitter API documentation
online.
In these cases you'll receive a call to requestFailed:withError: which will
include an NSError object detailing
the error. Twitter usually returns
meaningful HTTP error codes (like 404
for 'user not found', etc), and in
that case the -domain of the NSError
will be "HTTP" and the -code will be
the relevant HTTP status code. The
userInfo of the NSError will contain a
key "body" that may contain the
response body and "response" which
will contain the NSHTTPURLResponse.
This makes it really, really easy to
know what's happening with your
connections.

Objective-C: How to use xAuth?

I'm relatively new to Objective-C and am completely new to xAuth. Can somebody show me how or lead me to a tutorial to get a request access token pair and make a request to a URL given username, password, consumer_key, and consumer_secret?
I'm really foggy with this, and I don't even know why I get a access token pair (why two tokens, and how to both of them come into play?). Also, I already looked through a bunch of tutorials, but all of the good ones are for Twitter, and use some kind of Twitter engine. (I'm using xAuth for Foursquare, and their documentation can be found here.)
Thanks!
MGTwitterEngine is a great place for example code. You can use the OAuthConsumer project to help making xAuth calls.
If you checkout MGTwitterEngine.m (shown on Github) you can see in the function
- (NSString *)getXAuthAccessTokenForUsername:(NSString *)username password:(NSString *)password
creates an OAConsumer object with consumerKey and Secret and then creates an OAMutableURLRequest object, you'd use Foursquare's info there.
You should then be able to create a NSURLConnection with that request and then get your results in your standard delegate method, a la URL Loading System