I know there is lots of things given about twitter integration and private tweets.
But I want to know that if I use TWRequest in ios7 then it will work or not?
My code snippet as follows.
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
if(granted)
{
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
if ([accountsArray count] > 0) {
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
[tempDict setValue:#"rohit40793982" forKey:#"screen_name"];
//[tempDict setValue:#"true" forKey:#"follow"];
// [tempDict setValue:#"683286" forKey:#"user_id "];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:#"https://twitter.com/snehalikanksha/status/388535072359317504.json"]
parameters:tempDict
requestMethod:TWRequestMethodPOST];
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
NSLog(#"%#",urlResponse);
NSArray *tweets = [NSJSONSerialization JSONObjectWithData:responseData
options:kNilOptions
error:&error];
NSLog(#"%#",tweets);
NSString *output = [NSString stringWithFormat:#"HTTP response status: %i", [urlResponse statusCode]];
NSLog(#"%#", output);
[self performSelectorOnMainThread:#selector(displayText) withObject:output waitUntilDone:NO];
}];
}
}
}];
Can anybody help me ?
It gives Http error 403.
and log shows
"Your account may not be allowed to perform this action. Please <a class=\"js-reload\" href=\"#\">refresh the page</a> and try again."
I'm not sure of what you're trying to do but the reason why your code doesn't work is that you're not using a Twitter API endpoint.
If you want to get details for a specific tweet, you can use GET statuses/show/:id.
You would have to change your code for:
NSURL *url = [NSURL URLWithString:#"https://api.twitter.com/1.1/statuses/show.json?id=388535072359317504"];
TWRequest *request = [[TWRequest alloc] initWithURL:url
parameters:nil
requestMethod:TWRequestMethodGET];
The STTwitter library can help you in using the API by mapping every endpoint to an Objective-C method.
Related
I am using SLRequest to get user details and sharing on facebook and twitter. Also i am using Linkedin SDK and Google+ SDK to get user details on respective social networks. My questions are
Is it possible to give friend request on facebook using SLRequest?
Is it possible to follow a person on twitter using SLRequest?
Is it possible to connect a person on linkedin using SDK?
Is it possible to add a person on google+ using SDK?
if possible please give me a way to do that. Thanks.
After a long time, found the solution to my question,
For Facebook graph api version 2.0 does not support friend request (Refer:https://developers.facebook.com/docs/dialogs/friends/v2.0).
we can do it with twitter as follows
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
if ([accountsArray count] > 0) {
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
[tempDict setValue:#"MohammadMasudRa" forKey:#"screen_name"];
[tempDict setValue:#"true" forKey:#"follow"];
NSLog(#"*******tempDict %#*******",tempDict);
//requestForServiceType
SLRequest *postRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:#"https://api.twitter.com/1/friendships/create.json"] parameters:tempDict];
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:#"HTTP response status: %i Error %d", [urlResponse statusCode],error.code];
NSLog(#"%#error %#", output,error.description);
}];
}
}
}];
We can do it with Linkedin as follows.
NSURL *url = [NSURL URLWithString:#"http://api.linkedin.com/v1/people/~/mailbox"];
OAMutableURLRequest *request =
[[OAMutableURLRequest alloc] initWithURL:url
consumer:oAuthLoginView.consumer
token:oAuthLoginView.accessToken
callback:nil
signatureProvider:nil];
[request setHTTPMethod:#"POST"];
NSString *messageToPerson = #"/people/email=test123#test.com";
NSDictionary *person = [[NSDictionary alloc] initWithObjectsAndKeys:[[NSDictionary alloc] initWithObjectsAndKeys:messageToPerson,#"_path",#"test123",#"first-name",#"test",#"last-name",nil], #"person",nil];
NSArray *valueArray = [[NSArray alloc] initWithObjects:person,nil];
NSDictionary *values = [[NSDictionary alloc] initWithObjectsAndKeys:valueArray,#"values", nil];
NSDictionary *ir = [[NSDictionary alloc] initWithObjectsAndKeys:[[NSDictionary alloc] initWithObjectsAndKeys:#"friend",#"connect-type",nil], #"invitation-request",nil];
NSDictionary *update = [[NSDictionary alloc] initWithObjectsAndKeys:values,#"recipients",#"Invitation",#"subject",#"ConnectWithMe",#"body", ir, #"item-content", nil];
[request setValue:#"json" forHTTPHeaderField:#"x-li-format"];
[request setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
NSString *updateString = [update JSONString];
[request prepare];
[request setHTTPBodyWithString:updateString];
OADataFetcher *fetcher = [[OADataFetcher alloc] init];
[fetcher fetchDataWithRequest:request
delegate:self
didFinishSelector:#selector(postUpdateApiCallResult1:didFinish:)
didFailSelector:#selector(postUpdateApiCallResult1:didFail:) withPrepare:NO];
I unable to get details abt google plus add to circle.
I'm trying to get the user's Twitter timeline using the Twitter API in iOS SDK and got an error saying:
code = 92; message = "SSL is required";
I googled the error and I found this page on the Twitter API website, but I have no idea how to use it in iOS.
Here's my code:
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error)
{
if (granted == YES){
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0) {
ACAccount *twitterAccount = [arrayOfAccounts lastObject];
NSURL *requestAPI = [NSURL URLWithString:#"http://api.twitter.com/1.1/statuses/user_timeline.json"];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setObject:#"100" forKey:#"count"];
[parameters setObject:#"1" forKey:#"include_entities"];
SLRequest *posts = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:requestAPI parameters:parameters];
posts.account = twitterAccount;
[posts performRequestWithHandler:
^(NSData *response, NSHTTPURLResponse
*urlResponse, NSError *error)
{
// The NSJSONSerialization class is then used to parse the data returned and assign it to our array.
array = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
if (array.count != 0) {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"%#",array);
});
}
}];
}
} else {
// Handle failure to get account access
NSLog(#"%#", [error localizedDescription]);
}
}];
Is there a way to solve this problem?
Use "https" in your URL:
https://api.twitter.com/1.1/statuses/user_timeline.json
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
I have recently begun an Xcode project, and it requires me to get the feed, or timeline, from a Twitter account. I am following this tutorial. Although when I compile my code, it has no errors, it does not log any tweets. I also downloaded the source code for the project, but it still returns nothing. I realize that it could be a problem from my account, but I have tweeted something recently, followed some people, retweeted, basically everything you could do to update a timeline! Thanks for the help!
Twitter Account:#Pushahk
-(void)getTwitterFeed{
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error){
if (granted == YES) {
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0) {
ACAccount *twitterAccount = [arrayOfAccounts lastObject];
NSURL *requestAPI = [NSURL URLWithString:#"http://api.twitter.com/1.1/statuses/user_timeline.json"];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setObject:#"100" forKey:#"count"];
[parameters setObject:#"1" forKey:#"include_entities"];
SLRequest *posts = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:requestAPI parameters:parameters];
posts.account = twitterAccount;
[posts performRequestWithHandler:
^(NSData *response, NSHTTPURLResponse
*urlResponse, NSError *error)
{
// The NSJSONSerialization class is then used to parse the data returned and assign it to our array.
self.TwitterPosts = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"Hi");
for (int i = 0; i < [self.TwitterPosts count]; i++) {
NSLog(#"%#", [self.TwitterPosts objectAtIndex:i]);
NSLog(#"Hi");
}
});
}];
}
}
else{
NSLog(#"%#", [error localizedDescription]);
}
}];
}
It's because include_entities is no longer a valid parameter within the v1.1 API (it was in the v1 API). You may also need to provide a screen name, as I believe setting the .account property on the request is only for OAuth purposes.
Source: http://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
I need to get the person is following another person in twitter using the API.
I know the twitter migrated to v1.1
I used these API to get the relationship between two person,
https://api.twitter.com/1.1/friendships/exists.json?screen_name_a=Person1&screen_name_b=Person2
https://api.twitter.com/1.1/friendships/lookup.json?screen_name=Person1,Person2
But i get the final result is,
{
errors = (
{
code = 215;
message = "Bad Authentication data";
}
);
}
Is there any other exact API to find the my solution.
Any one help me to find the one person is following the another one.
Try this code you can get what you are expecting,
-(void) followUsOnTwitter {
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
// Get the list of Twitter accounts.
NSArray *accountsArray = [accountStore accountsWithAccountType:accountType];
// For the sake of brevity, we'll assume there is only one Twitter account present.
// You would ideally ask the user which account they want to tweet from, if there is more than one Twitter account present.
if ([accountsArray count] > 0) {
// Grab the initial Twitter account to tweet from.
ACAccount *twitterAccount = [accountsArray objectAtIndex:0];
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
[tempDict setValue:#"abcd" forKey:#"screen_name"]; // Change the Value String
[tempDict setValue:#"true" forKey:#"follow"];
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:#"https://api.twitter.com/1.1/friendships/create.json"]
parameters:tempDict
requestMethod:TWRequestMethodPOST];
[postRequest setAccount:twitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *output = [NSString stringWithFormat:#"HTTP response status: %i", [urlResponse statusCode]];
NSLog(#"%#", output);
if (urlResponse.statusCode == 200)
{
// follow by usr
}
}];
}
}
}];
}
you can check with this answer :
In the v1.1 API, they have replaced it with the friendships/lookup API where you can specify a comma separated list of up to 100 users and it'll tell you about the connections between the authenticating user and each of the users specified
I am able to send a tweet easily using TWRequest like this as per the apple example,
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountaccountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
// Request access from the user to access their Twitter account
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
// Did user allow us access?
if (granted == YES)
{
// Populate array with all available Twitter accounts
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
// Sanity check
if ([arrayOfAccounts count] > 0)
{
// Keep it simple, use the first account available
ACAccount *acct = [arrayOfAccounts objectAtIndex:0];
// Build a twitter request
TWRequest *postRequest = [[TWRequest alloc] initWithURL:
[NSURL URLWithString:#"http://api.twitter.com/1/statuses/update.json"]
parameters:[NSDictionary dictionaryWithObject:#"tweet goes here"
forKey:#"status"] requestMethod:TWRequestMethodPOST];
// Post the request
[postRequest setAccount:acct];
// Block handler to manage the response
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
NSLog(#"Twitter response, HTTP response: %i", [urlResponse statusCode]);
}];
but i was wondering if it is possible to use http://api.twitter.com/1/statuses/update_with_media.json in some way to send an image with the tweet instead of going via twitpic or another service. Or is there another way to send an image along with the tweet?
Thanks
It is possible.
You'll need to use addMultiPartData:withName:type: method for adding attributes for your tweet.
Status text won't be displayed until you add it as multipart data.
TWRequest *postRequest = [[TWRequest alloc] initWithURL:[NSURL URLWithString:#"https://upload.twitter.com/1/statuses/update_with_media.json"] parameters:nil requestMethod:TWRequestMethodPOST];
NSData *myData = UIImagePNGRepresentation(img);
[postRequest addMultiPartData:myData withName:#"media" type:#"image/png"];
myData = [[NSString stringWithFormat:#"Any status text"] dataUsingEncoding:NSUTF8StringEncoding];
[postRequest addMultiPartData:myData withName:#"status" type:#"text/plain"];