Use twitter ios sdk oAuth - cocoa-touch

I try to use MGTwitterEngine for twitter Iphone integration,
this is supporting both xAuth and oAuth as per its documentation
and firstly I try it using xAuth as which function I am calling named getXAuthAccessTokenForUsername
But my application is in developing stage .. and twitter not approving it .. they will approve it after release...
I am not able to use oAuth using MGTwitterEngine
Can anybody help me...
Even I am not able to use oAuth version from source
http://mobile.tutsplus.com/tutorials/iphone/twitter-api-iphone/comment-page-1/
I can update my status successfully using it...But not able do any thing else
I try
[_engine getUserInformationForEmail:#"battan20#gmail.com"];
//_engine is the twitterengine object
then getting error
Request 9EF8DE73-6E04-46F1-9D90-484F90FCA44F failed with error: Error Domain=HTTP Code=404 "The operation couldn’t be completed. (HTTP error 404.)"
Request 016DB024-1BFB-4E9B-8734-3FFCCB93D6E4 failed with error: Error Domain=HTTP Code=403 "The operation couldn’t be completed. (HTTP error 403.)"
Please help me
Amit Battan

When today I call
NSString *abc = [twitterObj getUserInformationFor:#"amit_battan"];
NSLog(#"abc...%#",abc);
Then I got the log
abc...F4BBA3C6-5783-46FF-A383-1B9C2319AB43
Request F4BBA3C6-5783-46FF-A383-1B9C2319AB43 succeeded
means it works ok...
But How I get the output.. in which function/variable

-(void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier {
NSMutableArray *mFollowerArray = nil;
mFollowerArray = [userInfo retain];
NSLog(#"count = %d",[mFollowerArray count]);
for (int i=0; i<[mFollowerArray count]; i++) {
NSLog(#" %#",[mFollowerArray objectAtIndex:i]);
}
}
above code might help

Related

LinkedIn Objective C sharing

we are working on sharing with the linkedIn objective C SDK, latest version.
Using this code:
NSString *url = #"https://api.linkedin.com/v1/people/~/shares";
NSString *payload = #"{\"visibility\":[{\"code\":\"anyone\"}],\"comment\":\"Check out developer.linkedin.com! http://linkd.in/1FC2PyG\"}";
if ([LISDKSessionManager hasValidSession]) {
[[LISDKAPIHelper sharedInstance] postRequest:url stringBody:payload success:^(LISDKAPIResponse *response) {
// do something with response
NSLog(#"Success: %#", response.description);
dispatch_async(dispatch_get_main_queue(), ^{
_responseLabel.text = response.description;
});
} error:^(LISDKAPIError *apiError) {
// do something with error
NSLog(#"Error: %#", apiError.description);
dispatch_async(dispatch_get_main_queue(), ^{
_responseLabel.text = apiError.description;
});
}];
}
lifted pretty much from their sample page. (Had to update a bit, the URL on the site was declared with initWithString which is no longer around).
We have requested and receive a valid session and requested the w_share permission as required in the updated spec.
Here is the actual error:
Error Domain=LISDKErrorAPIDomain Code=400 "(null)" UserInfo={LISDKAuthErrorAPIResponse=<LISDKAPIResponse: 0x1288cc100>}
Any hints would be appreciated!
According to Linked-in's docs and API Console, XML is the default and you need to specify that you want JSON, like this:
https://api.linkedin.com/v1/people/~/shares?format=json
And possibly with a header (not sure if the LISDKAPIHelper) knows how to do that part.
The documentation is really unclear. I suggest you capture the packets with something like CharlesProxy and see if what is getting sent is what you expect. Alternatively, use your same code, but send XML instead of JSON.

Suppressing Core Data errors from addPersistentStoreWithType:

I have a custom NSIncrementalStore. If there's a problem adding it, the error is automatically logged to the console.
The problem is that the options can contain sensitive data that I obviously don't want logged to the console.
I presume the error is logged by Core Data, which I don't really need, since I already have an NSError argument that I can use appropriately.
For example:
#implementation FakeStore
- (BOOL)loadMetadata:(NSError **)error {
*error = [NSError errorWithDomain:#"faildomain" code:531 userInfo:nil];
return NO;
}
#end
Attempt at adding the store:
[NSPersistentStoreCoordinator registerStoreClass:[FakeStore class] forStoreType:#"FakeStore"];
...
NSDictionary *options = #{#"option": #"sensitivedata"};
NSError *error;
[persistentCoordinator addPersistentStoreWithType:#"FakeStore" configuration:nil URL:storeUrl
options:options error:&error];
The error that is automatically logged to the console:
CoreData: error: -addPersistentStoreWithType:FakeStore configuration:(null) URL:<URL> options:{
option = sensitivedata;
} ... returned error Error Domain=faildomain Code=531 "The operation couldn’t be completed. (faildomain error 531.)" with userInfo dictionary {
}
A workaround is that the sensitive data shouldn't be passed into the options for my store, but it shouldn't be necessary.
Is there anyway to suppress this error?
well you can't turn it off but you should be able to redirect it. Bummer.. needs private API .. is that an option for you?
https://www.google.de/search?client=safari&rls=en&q=_NSSetLogCStringFunction&ie=UTF-8&oe=UTF-8&gfe_rd=cr&ei=uUKdVe-QN4nj8wfl9AE
tried the first link and found it still worked!
if private API is no option: no (and Id file a bug :D)

Unable to login PFUser or create PFObjects in OSX

Edit 1
Actually there's something more serious going on here as i am also not able to create and test objects.
So i have imported #import
Then i am calling the following from applicationDidFinishLaunching:
- (void)initParse {
[Parse setApplicationId:#"-----"
clientKey:#"-----"];
PFObject *testObject = [PFObject objectWithClassName:#"TestObject2"];
testObject[#"foo"] = #"barking";
[testObject saveInBackground];
}
With the correct application and client keys, but i am getting the following error logged in the console:
[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]
No idea why this is not working??
Thanks
Gareth
Ok, bit stumped on this one.
I have an OS X application, and i am trying to login a user using the following method in my viewController class, as follows:
- (IBAction)loginButton:(id)sender {
[PFUser logInWithUsernameInBackground:#"myname" password:#"mypass"
block:^(PFUser *user, NSError *error) {
if (user) {
// Do stuff after successful login.
NSLog(#"User Logged In");
} else {
// The login failed. Check error to see why.
NSLog(#"User Login failed");
}
}];
}
I have manually entered the username and password strings whilst troubleshooting.
Irrelevant of whether i set them to valid credentials or not the block never get's executed, if i set breakpoints none of them ever get hit, and none of the messages get logged.
Am i missing something? I don't see why this is not working. I have an iOS app setup with the same app id and key and that logs in using the same credentials fine, but this one will not.
Anyone got any ideas what's going on here?
Thanks
Gareth
Ok so for anyone else who hits this, it's because i wasn't including the Bolts.framework in my application.
Not mentioned anywhere in the Parse docs that this framework is needed. Dropped it in and like magic it started working.
Very unhelpful that there was nothing logged when it wasn't loaded from the Parse framework . . .
That's 8 hours of my life i'm never getting back!
Cheers
Gareth

Storing email in keychain impossible (KeychainItemWrapper)

I'm using the ARCified version of KeychainItemWrapper available at github, and I can't get it to store both email and password.
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:#"myApp" accessGroup:#"MY_APP.com.yourcompany.GenericKeychainSuite"];
[keychainItem setObject:[self.email dataUsingEncoding:NSUTF8StringEncoding] forKey:(__bridge id)kSecAttrAccount];
[keychainItem setObject:self.password forKey:(__bridge id)kSecValueData];
I works perfectly as long as I store an email... that don't have an at sign (#) it. Otherwise, I get the error
*** Assertion failure in -[KeychainItemWrapper writeToKeychain]
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'
Which comes from those lines
result = SecItemAdd((__bridge CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL);
NSAssert( result == noErr, #"Couldn't add the Keychain Item." );
Do you have any idea about what can be going wrong here ?
Thanks
Well, I just found the answer following the advice on that page iOS KeychainItemWrapper not updating, which is to add
[keychainWrapper setObject:#"Myappstring" forKey: (id)kSecAttrService];
I know its an old question, but that was happening to me and the above answers did not fix my problem. In my case I was accessing the keychain when the phone was locked.
Finally I got to solve it by using this just after init the keychain.
keychainWrapper.setObject(kSecAttrAccessibleAlways, forKey: kSecAttrAccessible)
It seems that keychain does not let you access it unless your phone is unlocked, by default.
More info here : http://b2cloud.com.au/tutorial/using-the-keychain-to-store-passwords-on-ios/

MGTwitterEngine Iphone oAuth

I hve try the MGTwitterEngine for oAuth from source https://github.com/kimptoc/MGTwitterEngine-1.0.8-OAuth
I am using this code for the MGTwitterEngine oAuth... but not working for me...
it give the same error I was getting in using xAuth without enabling xAuth Twitter integrated in Iphone App
Error Log is:
Twitter request failed! (3AFB8476-929F-4467-A4FE-DE43358CB62A) Error: The operation couldn’t be completed. (HTTP error 401.) ((null))
and one more thing I have not found anything in the for setting the application key and secret?
may be error due to this.. please help me.
Edited
Code on twitter button tab
-(IBAction)twitterBtnAct:(id)sender{
// Put your Twitter username and password here:
NSString *username = #"username";
NSString *password = #"password";
// Make sure you entered your login details before running this code... ;)
if ([username isEqualToString:#""] || [password isEqualToString:#""]) {
NSLog(#"You forgot to specify your username/password in AppController.m!");
}
// Create a TwitterEngine and set our login details.
twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
[twitterEngine setUsername:username password:password];
// Get updates from people the authenticated user follows.
[twitterEngine getFollowedTimelineFor:username since:nil startingAtPage:0];
}
Amit Battan
HTTP 401 errors are about authentication problems. In the project, the application does:
twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
[twitterEngine setUsername:username password:password]
Have you set this in your app?
I have use https://github.com/bengottlieb/Twitter-OAuth-iPhone for oAuth