Facebook Integration, iPhone - iphone

Facebook is not integrating with my application. even the sample codes are not working
Is facebook having some problem with iOS because the documentation and sample codes on developer.facebook also not found.

use this sharekit
it can integrate facebook, twitter, and much more apis

Try this new facebook grpah api
code for login on any button
fbGraph.accessToken = nil;
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:#"facebook"];
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}
[self loginButtonPressed:nil];

Related

facebook login using SDK

I am able to get the user profile permissions if user has set facebook account in his iPhone settings. For this I have used following code:
if(!_accountStore)
_accountStore = [[ACAccountStore alloc] init];
ACAccountType *facebookTypeAccount = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[_accountStore requestAccessToAccountsWithType:facebookTypeAccount
options:#{ACFacebookAppIdKey: #"app_id", ACFacebookPermissionsKey: #[#"email"]}
completion:^(BOOL granted, NSError *error) {
if(granted){
NSArray *accounts = [_accountStore accountsWithAccountType:facebookTypeAccount];
_facebookAccount = [accounts lastObject];
NSLog(#"Success");
[self me];
}else{
NSLog(#"go to iphone settings");
}
}];
-(void)me
{
NSURL *meurl = [NSURL URLWithString:#"https://graph.facebook.com/me"];
SLRequest *merequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
requestMethod:SLRequestMethodGET
URL:meurl
parameters:nil];
merequest.account = _facebookAccount;
[merequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSString *meDataString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(#"%#", meDataString);
}];
}
If user hasn't set his facebook account then control will move to else part i.e. go to iphone settings. In this else part I want to open the facebook login page so that user will be able to login in his facebook account without going to iPhone settings. SO how could we open the facebook login via SDK. Please help me out from this issue.
Thanks in advance.
In this case, if you're not using the user account (in case he/she doesn't have it set up on the iOS Settings), you need to implement the Facebook SDK (https://developers.facebook.com/ios/) on your application. It's easy, just follow these steps (https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/).
After that, you can use FBSession's method +openActiveSessionWithReadPermissions:allowLoginUI:completionHandler: to perform the user login.
To be true, in my application, I don't even try to login the user with Apple's requestAccessToAccountsWithType:options:completion:; with the newest Facebook SDK, the default behavior is:
Tries to login with the user account setup on the iOS Settings;
If no account is found, tries to open the Facebook application to request login / permissions;
If the Facebook app is not installed on the device, it opens Facebook on Safari, as a fallback.

cookies and session in iPhone

I want to set session and store values like cookies in the web browser in iPhone App. Is it possible? How can I implement this in iPhone? Can any one suggest a good solution..
Just set cookies like
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSHTTPCookie* testCookie = [NSHTTPCookie cookieWithProperties:
[NSDictionary dictionaryWithObjectsAndKeys:
#"1", NSHTTPCookieValue,
#"test_cookie", NSHTTPCookieName,
#".facebook.com", NSHTTPCookieDomain,
#"/", NSHTTPCookiePath,
nil]];
[cookies setCookie:testCookie];
And Get the cookies like
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie* cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
//here you can get you specific cookies
}

Basic authentication logout on iPhone

I have run into a little problem. I am connecting to a webservice that use Basic authentication and now I want the user to either: be able to log out, or that each time the request is made a new authentication is made. Right now the authentication seems to be cached. How do I do this?
I tried to append # at the end, but that did not seem to do the trick. The URL has the following format:
www.example.org/mywebservice/data
NSURL* url = [NSURL URLWithString: #"www.example.org/mywebservice/data"];
NSURLRequest* request = [[NSURLRequest alloc] initWithURL:url];
NSURLConnection* newConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
self.myConnection = newConnection;
[request release];
[newConnection release];
I think you want to clear the cache of the previous requests and every time want to do new request at login. So for that just put below code before doing request for login
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
[storage deleteCookie:cookie];
}
[[NSURLCache sharedURLCache] removeAllCachedResponses];
May help you
Happy Coding :)
I got it to work. I changed NSURLCredentialPersistenceSession to NSURLCredentialPersistenceNone.
NSURLCredential *cred = [[[NSURLCredential alloc] initWithUser:user.username password:user.password
persistence:NSURLCredentialPersistenceNone] autorelease];
Have you tried clearing the Authentication header in your NSURLRequest?
[urlRequest setValue:#"" forHTTPHeaderField:#"Authorization"];

How to clear cache and cookies in iphone

In my iPhone application I want to clear the cache and cookies at the logout page. Please give proper suggestions for that. Now I am using the below code, but it is not working properly.
[[NSURLCache sharedURLCache] removeAllCachedResponses];
I've been able to make it work using NSHTTPCookie and NSHTTPCookieStorage
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:#"facebook"]; //i used this to remove facebook related cookie so gave the domain name as facebook
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}
I've never actually worked with clearing cache, but used a piece of code which disables caching
NSURLCache *disableCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:disableCache];
[disableCache release];

App to display safari cookies on iphone

I want to make an app in iphone such that it displays the history of safari browser in iphone. Means I want to access safari cookies through other app. This is the first time m placing a query on overflow...... can anybody please let me know about this... please do reply
i don't know whether it will work or not but you can try this using NSHTTPCookie and NSHTTPCookieStorage classes...
code would be similar this
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSURL *URL;
NSArray *cookies;
NSString *cookieString = #"";
cookies = [cookieStorage cookies];
if([cookies count] > 0) {
NSHTTPCookie *cookie =[cookies objectAtIndex:0];
cookieString = [NSString stringWithFormat: #"%#=%#", [cookie name], [cookie value]];
NSLog(cookieString);
}