Custom iOS Tweet Sheet - ios

I am looking to have a custom looking tweet sheet to use in my application.
Obviously I can build my own and use the twitter API for posting; however, this would SEEM (Maybe its not THAT MUCH work, I can't say) to take a lot of work to build, especially in features like autocomplete for user twitter followers etc.
Is there anyway to customize the tweet sheet used by Apple's frameworks? It just looks god awful, especially compared to the design of my app.
If not, where can I look to implement the displaying friend results while typing in #user?
Any thoughts, idea's, links, suggestions would be great. Thanks in advance!

You can use Social.framework for signing your requests with data from accounts, which is in system.
Second step - make your own view for tweeting.
Third - get ACAccount.
Like this:
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *accountTypeTwitter = [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[store requestAccessToAccountsWithType:accountTypeTwitter options:nil completion:^(BOOL granted, NSError *error) {
if(granted) {
dispatch_sync(dispatch_get_main_queue(), ^{
NSArray *accounts = [store accountsWithAccountType:accountTypeTwitter];
//All twitter accounts are in array, show sheet to select one of them.
});
}
}];
Fourth - send SLRequest to twitter for post.
Example of SLRequest (to get information about user):
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"https://api.twitter.com/1.1/users/show.json?screen_name=%#",account.username]];
SLRequest *req = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:nil];
[req setAccount:account];
[req performRequestWithHandler:^(NSData *respData, NSHTTPURLResponse *resp, NSError *err){
//Req finished
}];

Here's a head start for your own custom tweet sheet:
https://github.com/doubleencore/DETweetComposeViewController

Related

Fetching twitter public feeds as JSON

As a part of my project I need to show the list of tweets in iOS app. I tried with the below code but its returning the JSON. The same code is works fine with version 1. Now the twitter api version is 1.1 and one another warning I got that TWRequest is deprecated. This deprecation is not the issue of this even I got same thing with SLRequest. Here my problem is I need to fetch the JSON of Particular user tweets without authentication or with authentication
TWRequest *postequest=[[TWRequest alloc]initWithURL:[NSURL URLWithString:#"https://api.twitter.com/1.0/statuses/user_timeline.json?screen_name=coolCracker&count=2"] parameters:nil requestMethod:TWRequestMethodGET];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output;
if ([urlResponse statusCode]==200) {
NSError *err;
NSDictionary *PublicTimeline=[NSJSONSerialization JSONObjectWithData:responseData options:0 error:&err];
output=[NSString stringWithFormat:#"HTTP response status: %li\nPublic timeline:\n%#",(long)[urlResponse statusCode],PublicTimeline];
}
else
{
output=[NSString stringWithFormat:#"No feed HTTP response was: %li\n",(long)[urlResponse statusCode]];
}
[self performSelectorOnMainThread:#selector(displayResults:) withObject:output waitUntilDone:NO];
}];
-(void)displayResults:(NSString *)text
{
NSLog(#"tweets feed %#",text);
}
I used this in my work and it worked pretty well. Use STTwitter. Download STTwitter files here.
Place this in your view didload:
STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:#"your consumer key"
consumerSecret:#"your secret key"];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {
[twitter getUserTimelineWithScreenName:#"your twitter account name"
successBlock:^(NSArray *statuses) {
self.twitterFeedList = [NSMutableArray arrayWithArray:statuses];
[self->listView reloadData];
} errorBlock:^(NSError *error) {
NSLog(#"%#", error.debugDescription);
}];
} errorBlock:^(NSError *error) {
NSLog(#"%#", error.debugDescription);
}];
Hi Below code is working for me. Though TWRequest is deprecated it works for now. Later you can change it to SLRequest.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *twitterType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to use their Twitter accounts.
[accountStore requestAccessToAccountsWithType:twitterType options:nil completion:^(BOOL granted, NSError *error) {
if (granted == YES){
//get accounts to use.
NSArray *accounts = [accountStore accountsWithAccountType:twitterType];
if ([accounts count] > 0) {
NSLog(#"account: %#", accounts);
ACAccount *loggedinaccount;
loggedinaccount = accounts[0];
// get tweets
TWRequest *postRequest=[[TWRequest alloc]initWithURL:[NSURL URLWithString:#"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=HuntEthane&count=2"] parameters:nil requestMethod:TWRequestMethodGET];
[postRequest setAccount:loggedinaccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output;
if ([urlResponse statusCode]==200) {
NSError *err;
NSDictionary *PublicTimeline=[NSJSONSerialization JSONObjectWithData:responseData options:0 error:&err];
output=[NSString stringWithFormat:#"HTTP response status: %li\nPublic timeline:\n%#",(long)[urlResponse statusCode],PublicTimeline];
}
else
{
output=[NSString stringWithFormat:#"No feed HTTP response was: %li\n",(long)[urlResponse statusCode]];
}
[self performSelectorOnMainThread:#selector(displayResults:) withObject:output waitUntilDone:NO];
}];
}
}else{
// show alert to inser user_name and password to login on twitter
UIAlertView *alertTwitterAccount = [[UIAlertView alloc]
initWithTitle:#"Enter with your twitter account"
message:nil
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"Login", nil];
[alertTwitterAccount setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
[[alertTwitterAccount textFieldAtIndex:0] setPlaceholder:#"User"];
[alertTwitterAccount setDelegate:self];
[alertTwitterAccount setTag:1];
[alertTwitterAccount show];
}
}];
Remember to add below frameworks to make this code work.
Twitter.FrameWork
Social.FrameWork
Accounts.Framework
Security.FrameWork
If you want to use SLRequest instead of TWRequest, replace request statement with below statement
SLRequest *postRequest = [SLRequest
requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodGET
URL:[NSURL URLWithString:#"https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=HuntEthane&count=2"]parameters:nil];
Moving forward the easiest way is adoption of Fabric.io from Tweeter as the development platform includes Tweeter embeds: https://get.fabric.io/native-social
"The easiest way to bring Twitter content into your app."
Honestly, I did not look into authentication part needed for Fabric.io.
Otherwise you need to follow and respect rules for accessing Twitter REST APIs or Streaming APIs, both well documented. OAuth authentication is required.
If you wish to avoid authentication in your app you can write a simple web REST API that will take care of authentication and serve (selected) tweets to your iOS app.
First, you’ll need to register an app with Twitter
Write down your Consumer Key and Consumer Secret
Write a simple server API (proxy) in your language of choice.
I personally prefer JavaScript on Node.js. Consider using libraries like express.js and oauth available on npm, but you can search npm for any other implemented Twitter proxy/API.
The code essentially consists of getting an OAuth Access token and then calling selected twitter APIs, and respecting ratelimits by caching results.

Posting status update to Twitter returns 403 forbidden error

I'm using the following code to try to post a simple status update to Twitter. Every time, I get a 403 forbidden error. I've tried it with multiple accounts and several different status messages. What am I missing?
ACAccount *account = [_accountsArray objectAtIndex:1];
ACAccountStore *account_store = [[ACAccountStore alloc] init];
ACAccountType *account_type_twitter = [account_store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
account.accountType = account_type_twitter;
NSURL *requestURL = [NSURL URLWithString:#"https://api.twitter.com/1.1/statuses/update.json"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:requestURL parameters:dataDict];
request.account = account;
[request performRequestWithHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {
NSLog(#"%#", response);
}];
Turns out I was signed out of my Twitter accounts in the Settings app, I guess because I had switched to a new phone. All my accounts were still showing up when I queried the ACAccountStore, though, so I had no reason to think they weren't authenticated. I'll leave this up in case anyone else makes the same dumb mistake.
I face the same error and fix it by reduce the message characters length to 140.
try this https://stackoverflow.com/a/35800216/5425082.
I was encountering this error just now while trying to post an image to the test account. Resolved it by shrinking the image from about 4MB to 1MB.

Facebook interests list not getting iOS

I am using SLRequest to get basic profile info. For getting interests i am using user_interests permission and the following code,
NSURL *meurl = [NSURL URLWithString:[NSString stringWithFormat:#"https://graph.facebook.com/me/interests"]];
SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:meurl
parameters:nil];
merequest.account = _facebookAccount;
[merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSError * error1=nil;
NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error1];
}];
But the above code gives the empty response like as follows,
{
"data": [
]
}
Can anyone give the solution for this problem. Thanks.
There could be only 2 possible reasons for this-
There are no interests of the user queried (as #Tobi has mentioned), or
Your access token used by your api call do not have the permissions user_interests. This could be because you've added this permission later and since the session was active it didnt asked for the new permission.
You can check what permissions you've granted to the app from here
If this is the problem, you can either logout from the facebook in your app and login again or delete the app from here so that it will ask for the authorization again.
Hope that helps. Good luck

Like a facebook page using ios 6.0 social api

I want to implement like a page functionality using ios 6.0 social api. I think if I get exact Facebook Graph API link for like functionality then it possible. But I am not getting what's the exact url. Many are saying that it's not possible. I would like to know exact answer.
Please check and below code and response from Facebook.
{
"error": {
"message":"(#100) Like actions are not yet supported against objects of this type.",
"type":"OAuthException",
"code":100
}
}
Code :
NSURL *meurl = [NSURL URLWithString:#"https://graph.facebook.com/me/og.likes?"];
NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:account.credential.oauthToken,#"access_token",#"https://www.facebook.com/sample",#"object", nil];
SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:meurl parameters:param];
merequest.account = account;
[merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *response = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(#"%#",response);
}];

ios6 Tweet via SLRequest and edit the source field

I'm trying to edit the "source" field of a tweet that's documented: https://dev.twitter.com/docs/platform-objects/tweets
The below code successfully posts a tweet, however when I pull up that tweet on tweetdeck it still says it's being posted via ios. It feels like NSDictionary isn't the place to be editing this, however it doesn't seem like there's a better place in the flow and I can't find any examples/documentation to clear it up. Thanks for any help in advance.
NSDictionary *message = #{#"status": contents,
#"source": #"App Name"};
NSURL *requestURL = [NSURL
URLWithString:#"http://api.twitter.com/1/statuses/update.json"];
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodPOST
URL:requestURL parameters:message];
postRequest.account = twitterAccount;
[postRequest performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
NSLog(#"Twitter HTTP response: %i", [urlResponse
statusCode]);
}];
The documentation you're referring to explains the meaning of returned fields.
You cannot set the source by yourself, there's no API for that.
You can find the POST statuses/update API here.
Additionally, the code you posted uses API version 1 which was shut-down a while ago.
Now you have to use API version 1.1.

Resources