簡體   English   中英

使用UIImage作為@“ picture”共享Facebook對話框

[英]Sharing facebook dialog by using UIImage as @“picture”

這是簡單的代碼

UIImage *ScreenShot = [self getScreenshot];

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"Name", @"name",
                               @"Caption.", @"caption",
                               @"Description.", @"description",
                               @"www.example.com", @"link",
                               ScreenShot, @"picture",               
                               nil];

[ facebook dialog:@"feed"
                  andParams:params
                andDelegate:self];

當我編譯它時收到此消息

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0x1288bb90' *** First throw call stack:

您無法將圖像直接上傳到牆上,而發布到牆上時,您只能將圖像鏈接到牆上。 因此,您需要先將UIImage上傳到某個地方。 您有2個選擇:

  1. 上載到您的/某些服務器並發布鏈接到它的牆貼。
  2. 上載到Facebook相冊。 檢查有關此操作的圖形API ,這非常簡單

我只是看了一下Facebook API,以了解您在這里做什么。 在我看來

http://www.facebook.com/dialog/feed?
  app_id=123050457758183&
  link=http://developers.facebook.com/docs/reference/dialogs/&
  picture=http://fbrell.com/f8.jpg&
  name=Facebook%20Dialogs&
  caption=Reference%20Documentation&
  description=Using%20Dialogs%20to%20interact%20with%20users.&
  redirect_uri=http://www.example.com/response

清楚地說出Facebook想要您做什么。 您是否看到picture參數本身不是圖像而是圖像的鏈接? 您必須先上傳圖像,然后將“ 鏈接到圖像”放入此參數。

我不確定這是否是您代碼中的唯一錯誤,但可以肯定這是一個主要錯誤。

將圖像導入到您的項目中,然后嘗試將行UIImage * ScreenShot = [self getScreenshot]更改為: UIImage *ScreenShot = [UIImage imageNamed:@"yourimage.png"];

如果可行,則您的“ getScreenshot”方法可能存在問題。

我將其用於我的應用程序:

    UIImage *ImageView = [UIImage imageNamed:@"anImage.png"];
        NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       ImageView, @"picture",@"Name", @"name",
                                       nil];

         //Let's post it
         [facebook requestWithGraphPath:@"me/photos"
         andParams:params
         andHttpMethod:@"POST"
         andDelegate:self];


-(void)request:(FBRequest *)request didLoad:(id)result{
    if ([result objectForKey:@"id"]) {


        UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"MyApp" message:@"Your image has been posted on your wall!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [al show];
        [al release];
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM