我正在做一個可以發送文本到Facebook的閱讀器應用程序。但我完成了在另一個頁面上登錄到Facebook。我有一個名爲'textpostingbtn
'的按鈕和一個包含文本的textview。我需要做的是,當用戶點擊按鈕時,它將文本發佈到Facebook而不顯示登錄對話框。我對按鈕進行了一些驗證,因此僅當用戶登錄時才啓用按鈕。link that i used in login purpose。如何在不顯示對話框的情況下發布到Facebook?
編輯:
- (IBAction)postGradesTapped:(id)sender {
//_posting = YES;
// If we're not logged in, log in first...
if (![_session isConnected]) {
self.loginDialog = nil;
_loginDialog = [[FBLoginDialog alloc] init];
[_loginDialog show];
_logoutButton.hidden = YES;
}
// If we have a session and a name, post to the wall!
//else if (_facebookName != nil) {
//[self postToWall];
//}
// Otherwise, we don't have a name yet, just wait for that to come through.
}
- (IBAction)logoutButtonTapped:(id)sender {
[_session logout];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"FB_logged"];
_btnFacebookmain.enabled =NO;
}
#pragma mark FBSessionDelegate methods
- (void)session:(FBSession*)session didLogin:(FBUID)uid {
[self getFacebookName];
}
- (void)session:(FBSession*)session willLogout:(FBUID)uid {
_logoutButton.hidden = YES;
_facebookName = nil;
}
#pragma mark Get Facebook Name Helper
- (void)getFacebookName {
NSString* fql = [NSString stringWithFormat:
@"select uid,name from user where uid == %lld", _session.uid];
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
[[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
}
#pragma mark FBRequestDelegate methods
- (void)request:(FBRequest*)request didLoad:(id)result {
if ([request.method isEqualToString:@"facebook.fql.query"]) {
NSArray* users = result;
NSDictionary* user = [users objectAtIndex:0];
NSString* name = [user objectForKey:@"name"];
self.facebookName = name;
_logoutButton.hidden = NO;
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FB_logged"];
[_logoutButton setTitle:[NSString stringWithFormat:@"Facebook: Logout as %@", name] forState:UIControlStateNormal];
/*if (_posting) {
[self postToWall];
_posting = NO;
}*/
}
}
請看看我的編輯問題,這是我如何登錄facebook.code, – ICoder
,如何從此代碼獲取令牌以及如何在我的發佈按鈕中設置另一個視圖控制器?謝謝 – ICoder
postgradetapped是Facebook的登錄按鈕 – ICoder