duanpanyang1962 2013-10-17 09:26
浏览 101
已采纳

在facebook ads api中获取图像的哈希码

I'm trying to get hash image using the Facebook Ads api. I didn't understand how to make the call. I have the image Url as string and the image itself as Byte[].

This is the example from FB documentation:

curl -F 'test.jpg=@test.jpg' -F 'access_token=_' "https://graph.facebook.com/act_368811234/adimages"

What is the test.jpg=@test.jpg means ? It's not something that I've seen before.

You can find the relevant Facebook documentation URL at: https://developers.facebook.com/docs/reference/ads-api/adimage/

Thank you

  • 写回答

1条回答 默认 最新

  • douwen7516 2013-10-18 03:10
    关注

    The following part of the curl request means post a parameter named test.jpg which references a local file path within the current directory called test.jpg.

    test.jpg=@test.jpg
    

    If you're using c#, you may want to take a look at the open source library available from facebooksdk.net (note, it's not produced by Facebook): http://facebooksdk.net/docs/making-synchronous-requests/

    Using this, it will likely be a couple of lines of code:

    var fb = new FacebookClient("access_token");
    string attachementPath = @"C:\\image.jpg";
    dynamic result = fb.Post("act_YOURACCOUNTID/adimages",
        new
        {
            file = new FacebookMediaObject
            {
                ContentType = "image/jpeg",
                FileName = Path.GetFileName(attachementPath)
            }.SetValue(File.ReadAllBytes(attachementPath))
        }
    );
    

    As you also tagged PHP, you can use the Facebook SDK which is produced by Facebook with the following code: https://github.com/facebook/facebook-php-sdk/

    $facebook = new Facebook(array(                                                                                       
      'appId'  => 'YOUR_APPID',                                                                                      
      'secret' => 'YOUR_APPSECRET',                                                                     
    ));                                                                                                                   
    $facebook->setAccessToken("YOUR_ACCESS_TOKEN");       
    $facebook->setFileUploadSupport(true);                                                                                
    $file='./test.jpg';                                                                                                   
    $args = array(                                                                                                        
         basename($file) => '@' . realpath($file),                                                                           
    );                                                                                                                    
    $response = $facebook->api('/act_YOURACTID/adimages','post',$args);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题