[英]Video post from iOS app to Facebook is not showing up on Facebook timeline
[英]adding a Post To Facebook Timeline from iOS APP
即時消息試圖使IBAction在用戶具有活動部分時在其時間線上發布。 我收到一條錯誤消息,指出: 函數“ x”的隱式聲明無效C99。 我一直在閱讀有關此問題的帖子,但沒有運氣,說實話,我不確定自己是否正確地做到了。 我更新了我的fb應用程序的權限,並從Graph API Explorer中獲取了目標代碼,但我不知道Im是否在我的代碼上正確實現了它。
這是我的發布方法:
-(void) aPost
{
NSMutableDictionary<FBGraphObject> *object =
[FBGraphObject openGraphObjectForPostWithType:@"website"
title:@"CR Taxi APP"
image:@"http://a4.mzstatic.com/us/r1000/047/Purple4/v4/05/cc/f2/05ccf23f-a409-1e73-a649-a5e6afc4e6eb/mzl.llffzfbp.175x175-75.jpg"
url:@"https://itunes.apple.com/cr/app/cr-taxi/id674226640?mt=8"
description:@"La nueva aplicación para llamar taxis!"];;
[FBRequestConnection startForPostWithGraphPath:@"{id_from_create_call}"
graphObject:object
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
// handle the result
}];
}
這是我的行動方法
- (IBAction)publishAction:(id)sender {
if ([FBSession.activeSession.permissions
indexOfObject:@"publish_actions"] == NSNotFound) {
NSArray *writepermissions = [[NSArray alloc] initWithObjects:
@"publish_stream",
@"publish_actions",
nil];
[[FBSession activeSession]requestNewPublishPermissions:writepermissions defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *aSession, NSError *error){
if (error) {
NSLog(@"Error on public permissions: %@", error);
}
else {
**not on the code //( error on this one) aPost(aSession, error);
}
}];
}
else {
// If permissions present, publish the story
**not on the code //(not an error on this one) aPost(FBSession.activeSession, nil);
}
}
請幫忙!
謝謝!
我猜編譯器錯誤實際上是“函數'aPost'的隱式聲明是無效的C99”,盡管您的操作方法代碼的格式寫得很奇怪。 編譯器僅在第一次遇到對aPost的函數調用時才會產生該錯誤消息。
aPost被編寫為沒有返回值且不帶參數的方法。 您試圖將其稱為C函數,並向其傳遞兩個參數,編譯器將其解釋為全新函數。 由於aPost是用所有硬編碼的字符串編寫的,因此您可能只想將調用更改為aPost(arg1,arg2);。 去[自己郵寄]; (提供的aPost和publishAction在同一類中)。
試試這個:可能對您有幫助
//將此行寫入ViewController.h文件中
@property (strong, nonatomic) NSMutableDictionary *postParams;
//在View Controller.m文件中
- (void)viewDidLoad
{
self.postParams =
[[NSMutableDictionary alloc] initWithObjectsAndKeys:
[UIImage imageNamed:@"Default.png"], @"picture",
@"Facebook SDK for iOS", @"name",
@"build apps.", @"caption",
@"testing for my app.", @"description",
nil];
[self.postParams setObject:@"hgshsghhgsls" forKey:@"message"];
}
- (IBAction)SharePressed:(id)sender {
@try {
[self openSession];
NSArray *permissions =[NSArray arrayWithObjects:@"publish_actions",@"publish_stream",@"manage_friendlists",@"read_stream", nil];
[[FBSession activeSession] reauthorizeWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
/* handle success + failure in block */
if (![session isOpen]) {
[self openSession];
}
}];
[FBRequestConnection startWithGraphPath:@"me/feed" parameters:self.postParams HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,id result,NSError *error) {
NSString *alertText;
if (error) {
alertText = [NSString stringWithFormat:@"error: domain = %@, code = %d, des = %@",error.domain, error.code,error.description];
}
else
{
alertText=@"Uploaded Successfully";
[self ResetAllcontent];
}
// Show the result in an alert
[[[UIAlertView alloc] initWithTitle:@"Result" message:alertText delegate:self cancelButtonTitle:@"OK!"
otherButtonTitles:nil]show];
}];
}
@catch (NSException *exception) {
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Please Login" message:@"For Sharing on facbook please login with facbook" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
[alert show];
}
@finally {
}
}
- (void)openSession
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
[appDelegate sessionStateChanged:session state:state error:error];
}];
ACAccountStore *accountStore;
ACAccountType *accountTypeFB;
if ((accountStore = [[ACAccountStore alloc] init]) &&
(accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook] ) ){
NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];
id account;
if (fbAccounts && [fbAccounts count] > 0 &&
(account = [fbAccounts objectAtIndex:0])){
[accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
//we don't actually need to inspect renewResult or error.
if (error){
}
}];
}
}
}
}
// =====在您的plist文件中執行URLTypes => Item 0 => URL Schemes => Item 0 => fbyourfacebookId
FacebookAppID-您的facebookID
是的,別忘了在developer.facebook.com上創建Facebook ID,並根據需要提供權限
- (IBAction)shareViaFacebook:(id)sender {
if (FBSession.activeSession.isOpen) {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"%@. Join on Linute.",self.userNameLabel.text], @"name",
//@"Build great social apps and get more installs.", @"caption",
locationString, @"description",
//@"http://www.linute.com/", @"link",
eventPicString, @"picture",//imageURL
nil];
// Make the request
[FBRequestConnection startWithGraphPath:@"/me/feed"
parameters:params
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
// Link posted successfully to Facebook
NSLog(@"result: %@", result);
} else {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"%@", error.description);
}
}];
}else{
FBSession *session = [[FBSession alloc] initWithPermissions:@[@"public_profile", @"email",@"user_friends",@"publish_actions"]];
[FBSession setActiveSession:session];
[session openWithBehavior:FBSessionLoginBehaviorWithFallbackToWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (FBSession.activeSession.isOpen) {
[self shareViaFacebook:nil];
}else{
[self shareViaFacebook:nil];
}
}];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.