How do you use OAuth to Twitter from an iphone app? - iphone

I'm looking for a simple example of how to send a Tweet from an iphone app. I've seen some very complex methods, but it can't be that difficult. I have registered the app with twitter, so I have the key & secret. Just need to know where to put these so I can send a status update and have it say "sent from MyApp".

http://github.com/bengottlieb/Twitter-OAuth-iPhone/tree/master

If you're using MGTwitterEngine you need to call the following method on your instance of MGTwitterEngine:
- (void)setClientName:(NSString *)name version:(NSString *)version URL:(NSString *)url token:(NSString *)token;
You might want to check out the version that explicitly supports OAuth.

MGTwitterEngine! Don't reinvent the wheel. Use either this (it's fantastically easy to use) or the CocoaRest library.

Related

Send info regarding user via XMPP in iOS

I have implemented the chat and everything is working good. I follow that link http://mobile.tutsplus.com/tutorials/iphone/building-a-jabber-client-for-ios-server-setup/ tutorial to implement chat app. Now i want to send info regarding user like photo,birthday,nickname etc. So i just want to create that info and send to other user.
I also want to send image(Data) to another user.
To set an avatar and other user-information you should have a look at the vcard extension XEP-0153 (specification and implementation).
You will find an example implementation for the vCard within the XMPPFramework iphone demo.
You would use the following calls to update and fetch vCards:
- (XMPPvCardTemp *)fetchvCardTempForJID:(XMPPJID *)jid;
- (XMPPvCardTemp *)fetchvCardTempForJID:(XMPPJID *)jid useCache:(BOOL)useCache;
- (void)updateMyvCardTemp:(XMPPvCardTemp *)vCardTemp;
To send binary data, you have some options. The XMPPFramework implements XEP-0065. There are other methods to send data like:
XEP-0066: Out of Band Data
XEP-0096: SI File Transfer
XEP-0234: Jingle File Transfer
Which you could probably implement as extensions and integrate them into the XMPPFramework.
In will integrate sending binary data like images and videos myself soon. So please leave a comment about your implementation.
first setup user profire in spark and then use [XMPPvCardTempModule myvCardTemp]

Any example on how to implement the new VerificationController and the KNOWN_TRANSACTIONS_KEY constant?

I've been looking at implementing the new VerificationController to verify in-App-Purchases:
http://developer.apple.com/library/ios/#releasenotes/StoreKit/IAP_ReceiptValidation/_index.html
And I wonder if there is some example anywhere en how to validate a transaction, since it seems that the - (BOOL)verifyPurchase:(SKPaymentTransaction *)transaction; is not enough and it has to be implemented internally to verify the purchase when the data form the server is received.
Another question is if anyone has a clue on what the KNOWN_TRANSACTIONS_KEY is and how to fill it, is it just the product id of the purchase?
In the file "VerificationController.m", check this function:
- (void)saveTransactionId:(NSString *)transactionId
we can see, KNOWN_TRANSACTIONS_KEY is a key to be wrote to NSUserDefaults. So we don't need to touch it.
login iTunes Connect > Manage Your Apps > (click your app) > Manage In-App Purchases > click the link View or generate a shared secret (at bottom-left of the page)
it'll show us:
A shared secret is a unique code that you should use when you make the
call to our servers for your In-App Purchase receipts.
Just click Generate.
You can find a complete implementation over here: https://github.com/evands/iap_validation
RayWenderlich.com Tutorial
This article, In-App Purchases in iOS 6 Tutorial: Consumables and Receipt Validation on the RayWenderlich.com site, offers a download of Apple's code but fleshed-out (including Base64 methods) and tweaked.
You need to perform the validation on a transaction when it changes to one of the completion states:
SKPaymentTransactionStatePurchased
SKPaymentTransactionStateRestored
call the function:
[[VerificationController sharedInstance] verifyPurchase:transaction];
As you say it is not enough to just look at the return value. The function is asynchronous. You need to add some code to VerificationController.m where it says:
#warning Validation succeeded. Unlock content here.
There are also a few other lines with #warning in VerificationController.m where you need to deal with errors.
As for base64 another library you might want to look at using is:
http://www.imthi.com/blog/programming/iphone-sdk-base64-encode-decode.php
When it comes to
KNOWN_TRANSACTIONS_KEY
and
ITC_CONTENT_PROVIDER_SHARED_SECRET
I too would like to know what they are for and why and when they are needed.

ShareKit for iphone - SHKShareTypeText

I am using ShareKit for iphone to share some text in facebook. Can any one tell me which delegate is called after publishing the text successfully. I need this to inform the user that his action was successful.
The shareDelegate property in SHKSharer isn't the easiest to get to and change, but there are notifications sent from the delegate methods of SHKSharer, one for each of the methods: SHKSendDidStartNotification, SHKSendDidFinish, SHKSendDidCancel, SHKSendDidFailWithError. Observing these notifications turns out to be a simple way of listening for the outcome of sharing.
See shareDelegate property of SHKSharer . All the concrete sharers (e.g. SHKFacebook) extend this base class.
Having said that, I'm not sure where you set a class to be the delegate using ShareKit's public API (so I'm not claiming this to be a complete answer).

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

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

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.