문제

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

도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top