p_panjwani
p_panjwani

Reputation: 17

Unable to implement Facebook Java APi

I need help with Facebook's marketing API. I'm trying to create an ad using Facebook Java API. I've email stored in my database, I want my program to take those email IDs and push them into custom audiences. But I am facing some problem with "AdCreative". It has two parameters named SetLinkUrl and SetObjectUrl. I am not understanding what to pass in those parameters. I tried giving the link to page what Im trying to promote but its not working.

For AdCreative part, this is what I'm doing.

AdCreative creative = account.createAdCreative()
                  .setTitle("Java SDK Test Creative")
                  .setBody("Java SDK Test Creative")
                 //.setImageHash(imageFile.hashCode())
                 .setLinkUrl("xyz")
                 .setObjectUrl("xyz")
                  .execute();

Here, xyz is link to my facebook page. I'm getting this error.

com.facebook.ads.sdk.APIException$FailedRequestException: {"error":{"message":"Invalid parameter","type":"OAuthException","code":100,"error_subcode":1885833,"is_transient":false,"error_user_title":"Ad Must Be Associated With a Facebook Page","error_user_msg":"Ads and ad creatives must be associated with a Facebook Page. Try connecting your ad or ad creative to a Page and resubmit your ad.","fbtrace_id":"HGmvidCVerR"}}
    at com.facebook.ads.sdk.APIRequest.readResponse(APIRequest.java:226)
    at com.facebook.ads.sdk.APIRequest.access$1(APIRequest.java:203)
    at com.facebook.ads.sdk.APIRequest$DefaultRequestExecutor.sendPost(APIRequest.java:409)
    at com.facebook.ads.sdk.APIRequest$DefaultRequestExecutor.execute(APIRequest.java:335)
    at com.facebook.ads.sdk.APIRequest.executeInternal(APIRequest.java:160)
    at com.facebook.ads.sdk.AdAccount$APIRequestCreateAdCreative.execute(AdAccount.java:1848)
    at com.facebook.ads.sdk.AdAccount$APIRequestCreateAdCreative.execute(AdAccount.java:1843)
    at demo.BasicExample.main(BasicExample.java:149)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://graph.facebook.com/v2.11/act_103127053798775/adcreatives
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection$10.run(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection$10.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
    at com.facebook.ads.sdk.APIRequest.readResponse(APIRequest.java:207)
    ... 7 more
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://graph.facebook.com/v2.11/act_103127053798775/adcreatives
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at java.net.HttpURLConnection.getResponseCode(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
    at com.facebook.ads.sdk.APIRequest.readResponse(APIRequest.java:205)
    ... 7 more

I just read somewhere that facebook doesn't allow facebook domain links to reduce spam. So I'm not understanding what to pass there. Please help me with that. Or if anyone can explain the whole "AdCreative" part, that would be great.

Also, I didnt understand the "Image hash" part. Please explain

Thanks.

Upvotes: 1

Views: 540

Answers (1)

bangdel
bangdel

Reputation: 2553

From the docs:

You will no longer be able to create or edit Event Ads and Link Ads that are not connected to a valid page. Requests will do so return the error: ErrorCode::ADPRO2__AD_MUST_HAVE_PAGE (1885833)

Also:

You can still create Event Ads and Link Ads if you provide a valid actor_id in the ad creative's object_story_id or object_story_spec fields

Upvotes: 1

Related Questions