TWRequest post reply NSURLErrorDomain - iphone

I am having trouble sending a reply to a tweet using TWRequest api. I am able to post a new tweet/status successfully but replies are failing with error below. Please advise
The error I receive on the reply post is:
Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed.
(NSURLErrorDomain error -1012.)" UserInfo=0x6c67900 {NSErrorFailingURLKey=https://api.twitter.com/1/statuses/update.json, NSErrorFailingURLStringKey=https://api.twitter.com/1/statuses/update.json,
NSUnderlyingError=0x6ce28a0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1012.)"}
Sample code below:
NSDictionary *paramDict = nil;
if(isReply)
{
paramDict = [NSDictionary dictionaryWithObjectsAndKeys:
in_reply_to_status_id, #"in_reply_to_status_id",
status, #"status",
nil];
NSLog(#"Status is %# %#",status,in_reply_to_status_id);
}
else
{
paramDict = [NSDictionary dictionaryWithObject:status forKey:#"status"];
}
TWRequest *sendTweet = [[TWRequest alloc]
initWithURL:[NSURL URLWithString:#"https://api.twitter.com/1/statuses/update.json"]
parameters:paramDict
requestMethod:TWRequestMethodPOST];
sendTweet.account = self.account;
[sendTweet performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse,
NSError *error) {
if ([urlResponse statusCode] == 200) {
dispatch_sync(dispatch_get_main_queue(), ^{
NSLog(#"Sent tweet: %#", status);
});
}
else {
NSLog(#"Problem sending tweet: %#", error);
}
}];

Stop looking for any help with TWRequest Twitter.framework is deprecated with iOS 6.0 For any
references do visit the dev.twitter.com
Use Social.Framework if you only need to post tweet or Images with tweet you can use SLComposeViewController for that purpose.
In Other Cases like replying to a tweet or favorite or even embedding Try this Singleton Class:
https://github.com/fhsjaagshs/FHSTwitterEngine
Read it's description do launch the demo and YOUR all set

Related

Get FaceBook Friends List error code = 100 "Invalid username. field"

I am using PARSE integration for facebook. I am able to successfully link the user to facebook but when i try to get facebook firiends list i get the following error.
FBRequest *request = [FBRequest requestForMyFriends];
// Send request to Facebook
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
}];
error code = 100
message = "(#100) Unknown fields: username."
type = OAuthException
desperately need help!!
The field username is no longer available with the Graph API v2.0, see https://developers.facebook.com/docs/apps/changelog#v2_0_graph_api
Endpoints no longer available in v2.0:
...
/me/username is no longer available.
-(IBAction)btnFacebookClick:(id)sender
{
NSArray *permissions = [[NSArray alloc] initWithObjects: #"user_about_me,user_birthday,user_hometown,user_location,email",#"read_mailbox",#"read_stream",nil];
[FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState status,NSError *error)
{
if(error)
{
NSLog(#"session error %#",error);
}
else if(FB_ISSESSIONOPENWITHSTATE(status))
{
[self getFriendList];
}
}];
}
-(void)getFriendList
{
FBRequest *friendsRequest=[FBRequest requestForMyFriends];
[friendsRequest startWithCompletionHandler:^(FBRequestConnection *connection,NSDictionary* result,NSError *error)
{
friendsArr = [result objectForKey:#"data"];
NSLog(#"friends description :%#",[friendsArr description]);
}];
}

How to post comment on photo using graph api in iphone?

I have the following code:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:txtComment.text, #"message", nil];
NSString *strPicId = [[Appdel.arrFacebookImages objectAtIndex:Appdel.getIndex] valueForKey:#"id"];
NSString *strPath =[NSString stringWithFormat:#"%#/comments",strPicId];
[FBRequestConnection startWithGraphPath:strPath parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result1, NSError *error)
{
if(!error)
{
}
else
{
NSLog(#"ERROR:%#",error);
}
}];
but when it runs, it giving me error like below,
ERROR:Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0xb36dd80 {com.facebook.sdk:HTTPStatusCode=403, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 200;
message = "(#200) Requires extended permission: publish_stream";
type = OAuthException;
};
};
I have successfully logged in and I am also getting photo albums, photos, comments, but I can't post any comment on any photo.
It looks like you are missing publish permission in your access token.
You can get it with:
[FBSession openActiveSessionWithPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if (FBSession.activeSession.isOpen && !error) {
// Publish the comment (your code inside) if permission was granted
[self publishComment];
}
}];
That was the code from: https://developers.facebook.com/docs/ios/publish-to-feed-ios-sdk/

Login using POST with RestKit returns 404 error

I'm totally new to RestKit and I'm trying to use a POST request to login to my system. I'm using RestKit version 0.20.3 and this is how I did:
- (IBAction)login:(id)sender {
NSString *email = [self.emailTextField text];
NSString *password = [self.passwordTextField text];
NSURL *url = [[NSURL alloc] initWithString:#"http://myhost.com/api.php"];
RKObjectManager *manager = [RKObjectManager managerWithBaseURL:url];
NSDictionary *tmp = #{#"rquest":#"user",
#"tag":#"login",
#"email":email,
#"password":password};
[manager postObject:tmp path:#"" parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSDictionary *result = [mappingResult dictionary];
if([[result objectForKey:#"success"] isEqualToNumber:[NSNumber numberWithInt:1]]){
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
[def setBool:YES forKey:#"isLoggedIn"];
// set user details...
[self.navigationController popToRootViewControllerAnimated:YES];
}
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
NSLog(#"Hit error: %#", error);
}];
}
As you can see, since I don't really need to map the response into an object, I tried to access the response data with NSDictionary. I'm not sure if this is the problem, but when I try to run the above code, I get the error:
013-10-06 11:24:51.897 Eateries[1182:454b] E restkit.network:RKResponseMapperOperation.m:304 Failed to parse response data: Loaded an unprocessable response (404) with content type 'application/json'
2013-10-06 11:24:51.902 Eateries[1182:1003] E restkit.network:RKObjectRequestOperation.m:243 POST 'http://myhost.com/api.php' (404 Not Found / 0 objects) [request=0.1479s mapping=0.0000s total=0.1648s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1017 "Loaded an unprocessable response (404) with content type 'application/json'" UserInfo=0x8ee81e0 {NSErrorFailingURLKey=http://myhost.com/api.php, NSUnderlyingError=0x8ef4ea0 "The operation couldn’t be completed. (Cocoa error 3840.)", NSLocalizedDescription=Loaded an unprocessable response (404) with content type 'application/json'}
2013-10-06 11:24:51.978 Eateries[1182:a0b] Hit error: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1017 "Loaded an unprocessable response (404) with content type 'application/json'" UserInfo=0x8ee81e0 {NSErrorFailingURLKey=http://myhost.com/api.php, NSUnderlyingError=0x8ef4ea0 "The operation couldn’t be completed. (Cocoa error 3840.)", NSLocalizedDescription=Loaded an unprocessable response (404) with content type 'application/json'}
I'm really confused because I don't really know what I did wrong here. If you have any suggestion, please kindly let me know. Thank you.
P.s: I changed the name of my host just for my personal purpose, but my server really responses ok with the request when I try to test it from other platforms.
You are using the wrong API.
postObject:... is meant for posting an object to be mapped, meaning that the object parameter - if not nil - will be used as target to map the response.
If you don't want to map the response, just use the underlying AFHTTPClient to perform a plain POST request.
[[RKObjectManager sharedManager].HTTPClient postPath:#"" parameters:tmp success:^(AFHTTPRequestOperation *operation, id responseObject) {
// ...
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// ...
}

AFNetworking PUT request Error 400

I am trying to make a PUT request using AFNetworking. There is a JSON on a remote location, which I want to update with the request.
I have managed to serialize my object into JSON, and I have put it an NSDictionary object:
NSDictionary *container = [NSDictionary dictionaryWithObject:[self notifications] forKey:#"notifications"];
This way when I print out the container using NSLog, I get precisely the JSON I want to send.
Then I try to use AFNetworking for my request:
AFHTTPClient *putClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:#"http://creativemind.appspot.com"]];
[putClient setParameterEncoding:AFJSONParameterEncoding];
NSMutableURLRequest *putRequest = [putClient requestWithMethod:#"PUT"
path:#"/notifications"
parameters:container];
AFHTTPRequestOperation *putOperation = [[AFHTTPRequestOperation alloc] initWithRequest:putRequest];
[putClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[putOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(#"Response: %#", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"Error: %#", error);
}];
[putOperation start];
When I try this solution, I get the following error message:
2013-08-10 16:10:40.741 NotificationReader[1132:c07] Error: Error
Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in
(200-299), got 400" UserInfo=0x75c89e0
{NSLocalizedRecoverySuggestion={"cause":null,"class":"java.lang.NumberFormatException","localizedMessage":"null","message":"null"},
AFNetworkingOperationFailingURLRequestErrorKey=http://creativemind.appspot.com/notifications>,
NSErrorFailingURLKey=http://creativemind.appspot.com/notifications,
NSLocalizedDescription=Expected status code in (200-299), got 400,
AFNetworkingOperationFailingURLResponseErrorKey=}
I think it's important to note that when I try the same request with nil parameters, I get te same error message. I also tried to perform a GET request on the same JSON to check if I can reach it and it works perfectly. I really have no idea what I could do. Any help would be appreciated

Facebook Graph API for iOS search

I am trying to search places from the GraphAPI using following code without luck. Can anybody please enlight my path ?
If I try to post link/message/photo it works as expected but when trying to get location it always fails and gives me **The operation couldn’t be completed. (facebookErrDomain error 10000.)**
//Following statement is using permissions
NSArray * permissions = [NSArray arrayWithObjects:#"publish_stream",#"user_checkins", #"friends_checkins", #"publish_checkins", nil];
[facebook authorize:FB_APP_ID permissions:permissions delegate:_delegate];
NSString *centerString = [NSString stringWithFormat: #"%f,%f", 37.76,-122.427];
NSString *graphPath = #"search";
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"coffee",#"q",
#"place",#"type",
centerString,#"center",
#"1000",#"distance", // In Meters (1000m = 0.62mi)
nil];
[facebook requestWithGraphPath:_path andParams:_params andHttpMethod:#"POST" andDelegate:_delegate];
Never mind. Downloaded latest sample HackBook from facebook for graph api from github and it includes sample code for the same.
For "search" you should use "GET" instead of "POST".
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#search
With Facebook iOS SDK, you can use FBRequestConnection after login.
[FBRequestConnection startWithGraphPath:#"search?q=coffee&type=place&center=37.76,-122.427&distance=1000"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Sucess! Include your code to handle the results here
NSLog(#"result: %#", result);
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(#"error: %#", error);
}
}];
With Last SDK
NSMutableDictionary *params2 = [NSMutableDictionary dictionaryWithCapacity:3L];
[params2 setObject:#"37.416382,-122.152659" forKey:#"center"];
[params2 setObject:#"place" forKey:#"type"];
[params2 setObject:#"1000" forKey:#"distance"];
[[[FBSDKGraphRequest alloc] initWithGraphPath:#"/search" parameters:params2 HTTPMethod:#"GET"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
NSLog(#"RESPONSE!!! /search");
NSLog(#"result %#",result);
NSLog(#"error %#",error);
}];