无法实施Facebook Java APi

时间:2017-11-22 12:22:14

标签: facebook facebook-marketing-api facebook-java-api

我需要Facebook营销API的帮助。 我正在尝试使用Facebook Java API制作广告。 我已将电子邮件存储在我的数据库中,我希望我的程序能够获取这些电子邮件ID并将其推送到自定义受众群体中。但我面临着“AdCreative”的一些问题。它有两个名为SetLinkUrl和SetObjectUrl的参数。我不明白在这些参数中传递什么。我试着给链接页面提供我试图推广的内容,但它不起作用。

对于AdCreative部分,这就是我正在做的事情。

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

这里,xyz链接到我的脸书页面。我收到了这个错误。

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

我刚刚读到某个地方,facebook不允许facebook域名链接减少垃圾邮件。所以我不明白该通过什么。请帮帮我。 或者,如果任何人都可以解释整个“AdCreative”部分,那就太棒了。

另外,我不理解“图像哈希”部分。请解释

感谢。

1 个答案:

答案 0 :(得分:1)

来自docs

  

您将无法再创建或修改未连接到有效网页的活动广告和链接广告。请求将返回错误:ErrorCode :: ADPRO2__AD_MUST_HAVE_PAGE(1885833)

此外:

  

如果您在广告素材的object_story_id或object_story_spec字段中提供有效的actor_id,您仍然可以制作活动广告和链接广告