问题
In the FB Graph API explorer the call to get business_discovery data uses the Instagram id for any user (in this case my own account) and uses a "username" to indicate the 3rd-party account from which one would like to get some public information.
Say for example, we want to get public data like name,followers_count,media_count for the instagram page motorolaus - the Graph Explorer the call would be something like:
GET /v3.2/?fields=name,username,business_discovery.username(motorolaus){name,followers_count, media_count}
But the restFB call IgUser.getBusinessDiscovery() does not take a username like the Graph API explorer. So how can i get the public info for an instagram page (which is NOT my own)? Thanks
回答1:
With hints from the helpful restFB folks, I can now answer my own question, in case others have the same question:
Basically, the name of the instagram page, for which, we want public data, has to be passed in during the fetch. The following code illustrates. Suppose we want to get public info from the "motorolaus" Instagram page.
// first you need to define the fields you want to fetch.
// For example, let's say we want the name, username,
// number of followers, number of posts(media) and the profile pic:
String businessDiscoveryFields = "business_discovery.username(motorolaus){name,username,followers_count,media_count,profile_picture_url}";
// Then we fetch the restFB IgUser object, using as id (1st parameter)
// the id of your Instagram business page, for which you got the
// access token. This is a string, formed by digits only.
IgUser igMyUser = facebookClient.fetchObject(my_instagram_bizpage_id, IgUser.class,Parameter.with("fields", businessDiscoveryFields));
// now we get the IgUser object for the page we want (motorolaus in
// this example), and from there we get the public data
IgUser igBizUser = igMyUser.getBusinessDiscovery();
System.out.printf("Instagram page %s (%s)\n", igBizUser.getName(), igBizUser.getUsername());
System.out.printf(" num followers: %s\n", igBizUser.getFollowersCount());
回答2:
The call you are looking for looks like:
IgUser user = fbClient.fetchObject("/",
IgUser.class,
Parameter.with("fields","name,username,business_discovery.username(motorolaus)
{name,followers_count, media_count}");
Afterwards the IgUser
object (user
) is filled with the desired values. I assume you have already a facebook client (fbClient
) present.
来源:https://stackoverflow.com/questions/53637555/how-do-i-use-restfb-iguser-getbusinessdiscovery