I am new to twitter4j and i try to fetch a couple of tweets, it all work fine except for the tweets with multiple pictures.
For example, if i tweet 4 pictures at the same time (yes now twitter allow us to tweet up to 4 pictures from their mobile application), i only manage to fetch the 1st picture.here is my code:
for (twitter4j.Status status : result.getTweets()) {
if (status.getMediaEntities() != null)
{
for (MediaEntity media : status.getMediaEntities())
{
//for some reason getMediaEntities() return an array with the first pic uploaded only
}
}
}
Tahnks for your help.
Just use status.getExtendedMediaEntities()
Related
I want to get all the uploaded photos of the logged in user that was uploaded today. I could fetch all the photos and filter it with the created_time field. But I would like to make the request to Facebook api to just send me todays photos.
This is the code I am using to get users uploaded photos
fun getAllPhotos() {
val bundle =Bundle()
bundle.putString(
"fields",
"album,alt_text,created_time,event,place,alt_text_custom,name,name_tags,target,source"
)
tempPhotos.clear()
val request = GraphRequest.newGraphPathRequest(
AccessToken.getCurrentAccessToken(),
"/me/photos/uploaded",
object : GraphRequest.Callback {
override fun onCompleted(response: GraphResponse) {
val type = object : TypeToken<ApiResponseObject>() {}.type
val respJSON = response.getJSONObject()
val item: ApiResponseObject = Gson().fromJson(respJSON.toString(), type)
item.data.forEach {
if (UtilityFunctions.checkIfToday(it.createdTime)) {
tempPhotos.add(it)
} else {
return#forEach
}
}
}
})
request.parameters = bundle
request.executeAsync()
}
As you can see I request for all photos to "/me/photos/uploaded/" I would like to only request for photos on a certain date ( or just today )
I saw that the response came sorted by created time so I returned from the loop whenever I saw some picture that was out of date.
Hey can you provide some more information regarding the issue you are facing with your code.
eg. some examples of how facebook api response structure is, some code snippets etc.
Edited response:
I crawled a while for the internet to search for your problem as it is difficult to create custom query in graph api and I have never used it before. What you are doing in your code is not bad either but if you insist on creating a custom query to api then I have found a github repository that might help you
Facebook Graph API query builder
I found the solution. I just needed to look into the pagination documentation
I found that just as fields I could also send since and a unix timestamp and it would return the photos uploaded since that timestamp
I am trying to implement Facebook app invite with this plugin in my ionic application. The implemented codes are following as below:
$scope.appInviteToFriend = function(user){
var url = "";
if (ionic.Platform.isAndroid())
{
url = "https://play.google.com/store/apps/details?id=com.example.application";
}
else if (ionic.Platform.isIOS())
{
url = "https://itunes.apple.com/nl/app/example-by-ionicapplication/id1983838444?l=en&mt=8";
}
var option = {
url: url,
picture : ""
};
facebookConnectPlugin.appInvite(
option,
function(obj){
if(obj) {
if(obj.completionGesture == "cancel") {
// user canceled, bad guy
} else {
// user really invited someone :)
}
} else {
// user just pressed done, bad guy
}
},
function(obj){
// error
console.log(obj);
}
);
}
When I executed these codes, the Facebook Invite Dialog opens and displayed app information correctly. But after click next button, select friend and also click send button, The error occurs. It says "Missing App Link URL. The app link used with this invite does not contain an Android or iOS URL.Developers are required to enter URl for at least one platform.". I've attached the error details with part of screenshot. Are these wrong the URLs which are store URL? How can I set the URLs?
You need to provide an App Link instead of a web URL. This link can be statically generated using Facebook's own tools, or you can generate them dynamically server-side. You can read more about these in the documentation.
Here's a tutorial that walks through setting up an Android app.
I am having trouble while trying to post a message on the current end-user Facebook wall with my Android Application.
So far :
The user is logged in with all the required permissions, especially
the publish_actions permission ;
I am using the last version of Facebook SDK 3.x & Graph API v2 as of May 2014
Post to wall works now as of EDIT 2, but there are issues with
privacy settings : post cannot be seen by anyone not even the
recipient who is tagged in the post ! See EDIT 2 for more details
Here is the documentation for posting a message on the user wall :
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/feed (go to Publishing)
Regarding the message that needs to be posted on the user' wall, I need to tag some friends that were previously selected by the user.
But to use the tag field I need to use the place field.
The documentation says :
Name: tags
Comma-separated list of user IDs of people tagged in this post. You cannot specify this field without also specifying a place.
Type: csv[string]
Name: place
Page ID of a location associated with this post.
Type: string
What is location page ID ? How do I get it ?
Oddly enough, in my specefic case, I am offering the possibilty to the user to share is upcoming travel on Facebook.
More oddly enough, this travel is defined by dates and a destination (name of destination + latitude & longitude). The user has the possibility to also share this travel to his friends that are located in his travel's destination hence the need to tag his friends to the wall post.
[EDIT 1]
After looking into #Tobi solutions, I managed to post a message on the end-user wall (in my case me, since I am the developper).
So far : the message is correctly displayed with a friend tagged (a dummy account I use for tests purpouses) and there is also the place : Paris, France.
Using the following search query (thanks #Tobi) search?q=Paris,France&type=place I can get the ID of Paris, France.
Since I did not code the part to retrieve the Place ID it put it manually in the code for the sake of testing the feature first.
[END OF EDIT 1]
[EDIT 2]
I noticed I forgot to add the part with the privacy values to my args Bundle. But it did not change a damn thing : my post is only visible to me alone.
Going to my Facebook wall, here is what I get :
Hovering the public parameters of the posts (a padlock icon) says "All tagged persons".
Clicking on the icon shows the list of settings with only "Only me" selected.
Why "only me" even though I specifically said me + my dummy account in the request parameters ?
Even weirder : changing the property of the publication parameters to "customized" with my dummy account does not change a damn thing as well. Just why ? Facebook is really getting on my nerve...
For the rest, the message content is correctly displayed and the related place is the good one. At least a got that correctly. But still, I just don't get the rest ...
[END OF EDIT 2]
So here is the updated code :
if (this.session != null && this.session.isOpened()) {
final Bundle args = new Bundle();
if (this.selectedContacts.isEmpty() == false) {
args.putString("message", message);
args.putString("place", "170558129707208"); //manually added Paris, France ID
String tags = "";
//here I made some modifications regarding the tags so that is built correctly
for (int it = 0; it < this.selectedContacts.size(); it++) {
final String name = this.selectedContacts.get(it).toString();
final String friendID = String.valueOf(getIdFromName(name)); // returns an int
if (it == this.selectedContacts.size())
tags += friendID;
else
tags += friendID + ",";
}
// Forgot to add privacy values to bundle !
final JSONObject privacyValues = new JSONObject(); //not android JSON, but JSON-Simple lib
privacyValues.put("value", "CUSTOM");
String allow = this.currentUser.getId() + "," + tags;
privacyValues.put("allow", allow); // to limit the visibility of this post
args.putString("privacy", privacyValues.toJSONString()); //forgot that one...
final Request shareTravelRequest = new Request(this.session, this.currentUser.getID() + "/feed",
args, HttpMethod.POST, new Request.Callback() {
public final void onCompleted(final Response response) {
//TODO
}
}
);
final Response response = shareTravelRequest.executeAndWait();
if (response.getError() == null) // in this case, no error occurred
return true;
else {
this.lastErrorMessage = response.getError().getErrorMessage();
Log.e("Something went wrong while posting Facebook message", this.lastErrorMessage);
Log.e("Error type is", response.getError().getErrorType());
Log.e("Error code is", String.valueOf(response.getError().getErrorCode()));
return false;
}
}
}
Unfortunately I must have mistaken somewhere because although the post does appear on my Facebook wall with my dummy account tagged and with the correct link to the place, my dummy account cannot see the post.
I tried creating manually the same post on my Facebook wall by using the following settings :
First I supplied a message
Second I supplied a place
Third I tagged my dummy account
Four I choose who can see this post : me and my dummy account
And finally, I post the message.
In this case, my dummy account sees the post both on its wall and on my wall.
So I would like to know what parameters I must get wrong because there is not much parameters and I just don't see why.
Thanks !
You can either use the Search and use the type place (https://developers.facebook.com/docs/graph-api/using-graph-api/v2.0#search), or, if you have positioning date, use an FQL query on the place table (https://developers.facebook.com/docs/reference/fql/place/) as described here: Facebook places: order results by distance
Use two test accounts made via Facebook Developer App settings and not a dummy account that breaks TOS. Since you request publish_actions you probably didn't submit the app for review. Unless your dummy account is a developer/tester in roles as well (which is breaking the TOS again) then your dummy account will not be able to see the post.
Only developers and testers of an unpublished application can see posts made by that application.
hello i just learn API Twitter in android. At the start of my application, is shows 20 tweets with this URL
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=name&count=20
I want to display the last 20 before 20 tweets that have been shown (with load endless) and all new tweet after tweet earlier 20 (with pull to refresh). but i don't know how the URL or method to get 20 last or newest tweet . how it's work ? sorry for my english.
You need this page: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline found on this well documented page (https://dev.twitter.com/docs/api/1.1)
The URI you likely want though is:
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=name&count=20&max_id=[lowest-id-from-last-batch]
If you're on Android I recommend using the Twitter4J library for easy Twitter API calls and response handling.
With use of Paging you can get the next 20 tweets (using Paging.page) or new tweets (using id's or time/since).
Code example for getting a Users timeline using Twitter4J in Android:
// Use as field
Twitter twitter;
// Get timeline
try {
if(twitter==null) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(Constants.DEBUG)
.setOAuthConsumerKey("YOUR CONSUMER KEY")
.setOAuthConsumerSecret("YOUR CONSUMER SECRET")
.setApplicationOnlyAuthEnabled(true)
.setHttpConnectionTimeout(5000)
.setHttpReadTimeout(5000)
.setHttpStreamingReadTimeout(5000);
twitter = new TwitterFactory(cb.build()).getInstance();
twitter.getOAuth2Token();
}
return twitter.getUserTimeline("TwitterName", twitterPaging);
} catch (Exception e) {
e.printStackTrace();
}
I'm following the documentation of google plus list and I am using this code:
Plus.Activities.List listActivities = plus.activities().list("me", "public");
listActivities.setMaxResults(5L);
// Execute the request for the first page
ActivityFeed activityFeed = listActivities.execute();
// Unwrap the request and extract the pieces we want
List<Activity> activities = activityFeed.getItems();
// Loop through until we arrive at an empty page
while (activities != null) {
for (Activity activity : activities) {
System.out.println("ID " + activity.getId() + " Content: " +
activity.getObject().getContent());
}
// We will know we are on the last page when the next page token is null.
// If this is the case, break.
if (activityFeed.getNextPageToken() == null) {
break;
}
// Prepare to request the next page of activities
listActivities.setPageToken(activityFeed.getNextPageToken());
// Execute and process the next page request
activityFeed = listActivities.execute();
activities = activityFeed.getItems();
This does not work because I have to create a client object. I tried more example but I do not understand how to do. Now:
How do I create a client object?
Where do I insert this client object?
I've seen a lot of answers but none work. You can Help me.
The comment that proceeded that code sample asked you to take a look at the Google+ Java quickstart, see the source file in question for how to set up your credentials and Plus client. You'll also need to authorize your request, that sample project shows how to use Google+ Sign-In to authorize the user to get an access token. You must have an authorized user to search with "me".
This sample is Java code using the Google Java API client library, the Android SDK doesn't include the client library by default, so you'd need to import that into your project.
I think you should take a look at this project : google API calendar
It works exactly like that with the G+ API.