facebook / facebook-java-business-sdk Goto Github PK
View Code? Open in Web Editor NEWJava SDK for Meta Marketing APIs
Home Page: https://developers.facebook.com/docs/business-sdk
License: Other
Java SDK for Meta Marketing APIs
Home Page: https://developers.facebook.com/docs/business-sdk
License: Other
Hi,
I'm trying to create an ad with all the Tracking settings in place. By all the tracking settings I mean pixel ID and URL parameters.
I tryed with something like this:
final ConversionActionQuery caq = new ConversionActionQuery();
caq.setFieldFbPixel(Arrays.asList("621916377890091"));
//formatter:off
final Ad ad = account.createAd()
.setName("Java SDK Test ad")
.setAdsetId(Long.parseLong(adSet.getId()))
.setCreative(creative)
.setStatus("PAUSED")
.setBidAmount(100L)
.setRedownload(true)
.setTrackingSpecs(Arrays.asList(caq))
.execute();
//formatter:on
but I get the StackOverflow exception
Caused by: java.lang.StackOverflowError: null
at java.lang.Class.isPrimitive(Native Method) ~[na:1.8.0_65]
at com.google.gson.internal.$Gson$Types.checkNotPrimitive($Gson$Types.java:432) ~[gson-2.3.1.jar:na]
at com.google.gson.internal.$Gson$Types.access$000($Gson$Types.java:43) ~[gson-2.3.1.jar:na]
at com.google.gson.internal.$Gson$Types$WildcardTypeImpl.<init>($Gson$Types.java:542) ~[gson-2.3.1.jar:na]
at com.google.gson.internal.$Gson$Types.canonicalize($Gson$Types.java:109) ~[gson-2.3.1.jar:na]
at com.google.gson.internal.$Gson$Types$WildcardTypeImpl.<init>($Gson$Types.java:551) ~[gson-2.3.1.jar:na]
at com.google.gson.internal.$Gson$Types.canonicalize($Gson$Types.java:109) ~[gson-2.3.1.jar:na]
at com.google.gson.internal.$Gson$Types$WildcardTypeImpl.<init>($Gson$Types.java:544) ~[gson-2.3.1.jar:na]
at com.google.gson.internal.$Gson$Types.canonicalize($Gson$Types.java:109) ~[gson-2.3.1.jar:na]
Any tips on how to make it work with the current SDK?
Thanks!
Error Message: Object with ID 'act_5620100000000975' does not exist
I think you need remove "act_" in request.
Hi ,
I'm using java sdk v0.4. It seems like there has no method to allow me to list all businesses belongs to the user. So I just use the following code as alternative:
APIRequest<Business> request = new APIRequest<Business>(context, "me", "/businesses", "GET",Business.getParser());
The API response correctly as expect:
{"data":[{"name":"Alibaba advertising","id":"7349984ACCOUNTID72"}],"paging":{"next":"https://graph.facebook.com/v2.8/130101310692072/businesses?access_token=MY_ACCESS_TOKEN&limit=25&offset=25&__after_id=enc_AdCRaZCZAD9ZAbIQDB7lYwCoNqAaNcqRbEWaRPZCHaPS8eSxQ11pUw7nHnOC1ZCBGm6moP4vaYSOp3D132M032XHZBUG3P"}}
But this line of code throws a NullPointerException which I think it shouldn't:
JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
The above code can be found at Business.java, line 163.
Would you be kindly to take a look? Thanks a lot.
-Peng
Better than just making jars available for download
You should consider testing it with more versions - maybe 2 versions (so apps that use a different version of gson). For us it's not an issue.
Your pom should specify which versions are acceptable.
e.g.:
[2.4,2.5]
This is low priority from our end (since it does not collides) but might be an issue for an app that is using gson on different version then 2.5
Sample code to create a campaign listed on the main Code page on Github, doesn't work. Sample code within the Examples folder for QuickStartExample, doesn't work.
Does anyone have any working sample code to get this working?
I haven't ran a wireshark (too lazy), but I seem to be running into the issue with 200 requests per hour max over an account with only 25 ads.
I have code that looks like this:
APINodeList ads = adAccount.getAds()..[blah blah blah]..execute() (1 call, returns 25 ads)
Then I go through all ads, requesting insights:
for (Ad ad : ads) {
APINodeList adInsights = ad.getInsights().[blah].execute() (should get called 25 times)
methodThatExaminesInsights(each adInsight)
}
Now considering there should be only 26 calls to go to backend, I getthe 200-max error after going through 180 or so insights. Which means that looking at an insight generates a call?
This seems silly as that means there is no way to examine even a single account's insights
Seems like a bug.
Any help would be appreciated.
Hi.
How do I load all the saved audiences? I managed to load custom audiences with account.getCustomAudiences().requestField("name").execute();
but I don't get the saved audiences.
I see that there is an endpoint for loading saved audiences by id: https://developers.facebook.com/docs/marketing-api/reference/saved-audience/
but how do I get the IDs? :)
Best,
M
I was unable to find enums or documentation on targeting adverts on Facebook.
For eg: "setFieldGenders( )" takes a list of long as an arguments but its not clear which number corresponds to which gender, can you point me to a documentation which I can refer for these cases?
Thanks in advance.
Pushkar
Hi,
Does the SDK support autocomplete search for targeting objects such as (location, locale..)
I was trying to use APIRequestGetTargetingSearch class, but couldn't execute on AdAccount Node.
Basically I'm trying to build query like this: search?q=un&type=adgeolocation
Please let me know if I misunderstanding about this functionality.
Thanks,
Uploading of video captions fails due to the way the default request executor determines mime types based on file extension; it uses a fixed mapping that doesn't include ".srt", so the Facebook API endpoint rejects the request.
A more foolproof method would be to fall back to a default mimetype such as "application/octet-stream" when one can't be determined based on file extension. Files.probeContentType could also be utilized to delegate to more sophisticated user supplied file type detectors such as Tika.
Hi, it seems like current package only supports java 1.8+, while some of our exists projects are using 1.7 or older. It requires a lot of extra works to upgrade all our projects to java 1.8. Would you plan to support java1.7 in the future?
Hi
i try to put 'madid'( Android advertising ID) to custom audience.
and i want to know limitation of user's data.
if i had tried to put 30000 data,
i got {"error":{"code":1,"message":"An unknown error occurred","error_subcode":99}}
so could you let me know limitation of added user.
When creating an AdCreative, passing an instance of AdCreativeLinkDataCallToActionValue to adCreativeLinkDataCallToAction.setFieldValue(..) doesn't have an effect - those CTA parameters are not present in the resulting adCreative.
Instead, we are forced to use the form adCreativeLinkDataCallToAction.setFieldValue(String s), and pass in json in a string - only then do we see the correct CTA parameters on the resulting adCreative.
0.4.0 AdsInsights can not get all breakdown data "age","country","gender","impression_device" and other.
Hi,
I'm not sure it's right place to post this question, it seems happening to python SDK as well.
For me I'm using this java-sdk to develop my app. So I just want to post here, in case any one can take a look and advise.
I'm trying to get ad-preview for a link ad based on
https://developers.facebook.com/docs/marketing-api/reference/ad-creative-link-data/
"The preview iframe received doesn't render creative but showing:
Using unsupported field in object_story_spec: The field force_single_link is not supported in the field link_data of object_story_spec."
Can you advise what need to be done for this field: force_single_link?
I've tried different cases: remove this field from object_story_spec, set true or false, but still having same error.
AdCreative creative = new AdCreative();
AdCreativeObjectStorySpec objStorySpec = new AdCreativeObjectStorySpec();
AdCreativeLinkData linkData = new AdCreativeLinkData();
linkData.setFieldLink(obj.getString("link_url"));
//linkData.setFieldForceSingleLink(false);
linkData.setFieldImageHash(obj.getString("image_hash"));
objStorySpec.setFieldLinkData(linkData);
objStorySpec.setFieldPageId(obj.getString("page_id"));
creative.setFieldObjectStorySpec(objStorySpec);
Thanks
Sang
Hi,
In the previous version, I could get pages' tabs from ConnectionObject node.
In 2.6, I couldn't get this object from account (page) node, as it throws exception:
" Requires either an app access token, or a page access token for this Page"
Is that intended feature? I'm able to get promotable_posts from this node, so just want to double check.
Thanks.
User user = new User(fbUserId, context);
APINodeList<APINode> accountList = user.getAccounts()
.requestField("id")
.requestField("name")
.requestField("promotable_posts")
//.requestField("tabs") //require page accesstoken
.requestField("picture").execute();
As title. The method's parameter type should be java.io.File not java.lang.String. As my understand is not correct, please correct me, thanks.
Please use HttpURLConnection instead of HttpsURLConnection. This is giving ClassCastException in weblogic. Working fine when I changed to HttpURLConnection .
You should never explicitly import/use Sun Java SE implementation specific classes in your code.
Link to similar issue:
http://stackoverflow.com/questions/3038026/using-java-class-httpsurlconnection
The package currently uses a PrintStream instance for logging. IMO it would be better to use slf4j, which gives consumers control over which logging framework is used, how logging is done, finer grained control over which kinds of messages are logged, etc.
VideoUtils.waitForVideoEncoding will continue retrying even when the call to getVideoStatus indicates that there was an error (it only ever checks if the status is "ready"). It should probably instead return false or throw an exception.
can you help me to get the ads of a campaign using the facebook java API.
and can u also provide a proper documentation for the facebook-java-ads-sdk.
Reference https://developers.facebook.com/docs/marketing-api/reference/ads-insights. The AdInsights Object is missing the estimated_ad_recall_rate and objective fields
Hello,
Is there any chance that the 50 requests limit per batch could be increased ?
Thank you !
Kind Regards !
Catalin
I get a decent amount of transient errors while calling the Facebook api. Immediate retries of the same request work. It would be nice to add retry support into the sdk, possibly in APIRequest.callInternal(). The response has the is_transient field in it, if this is true it would be nice if the sdks retried instead of all calling clients to have to catch the APIException, check if it it is transient and then retry everywhere a request is made. Making this optional by adding a boolean (retry) with the number of retry attempts to the APIContext would allow for users to turn retries on or off.
Exception from sdks:
com.facebook.ads.sdk.APIException: {"error":{"message":"An unexpected error has occurred. Please retry your request later.","type":"OAuthException","is_transient":true,"code":2,"fbtrace_id":"DAbvR5wiN2d"}}
When upload the video, we want to show upload progress bar, so how to get the progress percent from FaceBook?
Hi there
Why do you support OptimizationGoal 'Clicks' in AdSet (EnumOptimizationGoal)? This feature isn't supported by the facebook api since version 2.4.
@SerializedName("CLICKS")
VALUE_CLICKS("CLICKS")
If it's a failure, I will create a PR.
Thanks in advance.
Kind regards, Patrick
There is no documentation regarding Error Handling.
Suggest you add some.
@christinelu FYI
It would be nice if VideoUtils exposed a stream-based API for uploading videos, as opposed to only offering a File based one as it does now. This can be achieved with a minor refactoring of the existing code, where the File-based methods delegate to a stream-based one.
APIRequest delegates to IRequestExecutor to make all HTTP calls; currently a default implementation is used and stored in a static field in APIRequest, with static methods which can be used to override it.
This makes it awkward for testing, as you then have global state you need to setup and teardown, which also precludes parallelizing test runs. It also makes it impossible to use different IRequestExecutors for different kinds of requests without synchronization or some sort of coordination (admittedly I don't have a use case for this).
Wouldn't it make more sense for the IRequestExecutor configuration to live somewhere else, for example APIContext?
Although it seems like it is designed for supporting multiple versions of the API I see few issues:
Hope this makes sense
@christinelu FYI
There is no guide or example for creating & using custom audience. Uploading Custom audience of phone number, email, Mobile advertising ID etc.
Hi,
I'm still using v2.6 and I got this error while creating ad with url_tags having more than 1 value:
creative to submit:
{"body":"test desc","image_hash":"c6e035cb89c48000b7e5eb8af0e2b012","link_url":"http://sdinh.net","object_url":"http://sdinh.net","title":"my headline","url_tags":"key=1&key=2"}
error:
{\"message\":\"(#100) Creative spec must be an associative array (optionally json-encoded)
It happened with different type of creative (Domain, Post page ad...).
Can you take a look and advise.
Thanks,
Sang
I have a set of audiences name, but not audience id.
How can I get the size of each audience, audience type and audience id.
Example: I have exactly name of audience: "Design Engineer". I want to get audience type is "work_positions", audience id is "109542932398298" and audience size is "105197"
Thanks !
hi
Would like to know is there any way to I duplicate ads, ad sets or campaigns in sdk , similar to Power Editor.
It will be very helpful.
Hi, I think that a lot of Java/Scala developers would love to use this project. So should we support them with an Async API? For example, we can use Retrofit to support Observable API calls (this is just an example, we don't have to use it).
The main point is this project will mostly be used by some backend projects. And with them I think that providing some Observable or CompletableFuture APIs is really a need.
I can also help to develop some code. :)
It looks like all of the objects in com.facebook.ads.sdk.* have the same static, synchronized method for constructing the Gson object:
synchronized /*package*/ static Gson getGson() {
if (gson != null) {
return gson;
} else {
gson = new GsonBuilder()
.excludeFieldsWithModifiers(Modifier.STATIC)
.excludeFieldsWithModifiers(Modifier.PROTECTED)
.disableHtmlEscaping()
.create();
}
return gson;
}
Gson instances are threadsafe, and therefore a single instance could be shared throughout the codebase. Maybe the APIContext can grow a method for getting the Gson instance? It would also make it easier for consumers to override the defaults.
Is there any option to setup proxy settings in sdk/api, because most of organization have proxy server for Internet access. Thanks
Currently, ajax error message is:
responseText: "{"success":false, "code": 13, "message": "{"error":{"message":"Invalid parameter","type":"OAuthException","code":100,"error_data":{"blame_field_specs":[["daily_budget"]]},"error_subcode":1885272,"is_transient":false,"error_user_title":"Your Budget Is Too Low","error_user_msg":"The minimum budget for this ad set is $19.90.","fbtrace_id":"B8zThZN6jAv"}}"}"
Which cannot parse by JSON.
The correct one should be: (removing the double quote around responseText.message
{"success":false, "code": 13, "message": {"error":{"message":"Invalid parameter","type":"OAuthException","code":100,"error_data":{"blame_field_specs":[["daily_budget"]]},"error_subcode":1885272,"is_transient":false,"error_user_title":"Your Budget Is Too Low","error_user_msg":"The minimum budget for this ad set is $19.90.","fbtrace_id":"B8zThZN6jAv"}}}
Hi guys,
This SDK is really handy however its missing one big feature, if we want to upload data to the /act_<AD_ACCOUNT_ID>/partnerdata
endpoint its not supported. Are there plans to add this one in?
https://developers.facebook.com/docs/marketing-api/data-partners-api
Thanks!
Hi team,
Just have a question, how does pagination work for cases like below:
APIResponse res = new APIRequest<APINode>(context, "", "search", "GET").execute(params);
Please advise.
Thanks,
Sang
Hello,
My application receives FailedRequestException exception, when it tries to AdAccount.fetch()
Exception: com.facebook.ads.sdk.APIException$FailedRequestException: {"error":{"message":"(#100) Tried accessing nonexisting field (last_used_time) on node type (AdAccount)","type":"OAuthException","code":100,"fbtrace_id":"GHeibz8E4TY"}}
at com.facebook.ads.sdk.APIRequest.readResponse(APIRequest.java:223)
at com.facebook.ads.sdk.APIRequest.access$100(APIRequest.java:44)
at com.facebook.ads.sdk.APIRequest$DefaultRequestExecutor.sendGet(APIRequest.java:344)
at com.facebook.ads.sdk.APIRequest$DefaultRequestExecutor.execute(APIRequest.java:322)
at com.facebook.ads.sdk.APIRequest.executeInternal(APIRequest.java:157)
at com.facebook.ads.sdk.AdAccount$APIRequestGet.execute(AdAccount.java:12225)
at com.facebook.ads.sdk.AdAccount$APIRequestGet.execute(AdAccount.java:12220)
at com.facebook.ads.sdk.AdAccount.fetchById(AdAccount.java:187)
at com.facebook.ads.sdk.AdAccount.fetch(AdAccount.java:173)
It seems that facebook changed schema, and now they are not returning 'last_used_time' field
java SDK should be changed accordingly.
Thanks,
Is there any way to quickly duplicate the adsets with its ads and ad creative?
https://developers.facebook.com/docs/graph-api/reference/audience-insights-query/
How do I access this via my app? Would I have to request ads_management? read_insights? ads_read?
Is it normal?, I just did follow the examples of how to paginate but instead of using campaigns I used adinsights. For now I check the size of the node list to end the loop.
Thanks.
Business.java, row 149, inside parseResponse():
JsonObject paging = obj.get("paging").getAsJsonObject().get("cursors").getAsJsonObject();
This causes a null pointer exception in API when trying to fetch all businesses of a user like this:
APINodeList<Business> x = (APINodeList) ((APINodeList) (new APIRequest(context, "", "/me/businesses", "GET", Business.getParser())).execute());
Reason is that the API endpoint in question doesn't return cursors.
https://developers.facebook.com/docs/marketing-api/reference/ad-account/audience_insights_query
Are are there plans to support this API?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.