How to get facebook page's stream with facebook-android-sdk - android

I followed steps here: https://developers.facebook.com/docs/guides/mobile/#android
but I really don't get how use Graph API to get a Page's stream (only news) for Android.
Someone can make me an example? I cannot also find a real good example online searching with Google...

There's a good Graph API explorer here, getting a page info is simple as using GET request with the page id.
https://graph.facebook.com/<PAGE_ID>
So you can use the Simple Sample found here
//Page id for Bristol (my hometown) but could use something like 'cocacola'
String PAGE_ID="108700782494847"
mBristolPageButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//get the request aysn and process JSON response with the Listener
mAsyncRunner.request(PAGE_ID, new MyPageRequestListener());
}
});
To get the feed/news from a page put /feed on the end [However you may require a auth_token to get news stream]
https://graph.facebook.com/<PAGE_ID>/feed

Related

Android - ConsentInformation - Could not parse Event FE preflight response

I ve seen this error posted in many places but no one has ever answered what needs to be done to fix it or why is it happening. I m hoping I ll have better luck.
ConsentInformation consentInformation = ConsentInformation.getInstance(getActivity());
String[] publisherIds = {"pub-**********~*******"};
consentInformation.requestConsentInfoUpdate(publisherIds, new ConsentInfoUpdateListener() {
#Override
public void onConsentInfoUpdated(com.google.ads.consent.ConsentStatus consentStatus) {
//do something
}
#Override
public void onFailedToUpdateConsentInfo(String errorDescription) {
Log.e("GDPR ", errorDescription);
}
});
This is how I am using the consent sdk. I always get the same error: Could not parse Event FE preflight response
My import in gradle is implementation 'com.google.android.ads.consent:consent-library:1.0.6'
I am running this code on the OnCreateView method of the first fragment loaded. Also tried running a few seconds later in case it was a timing thing...still the same error.
Also tried adding the ca-app- prefix before the pub in publisher id...same result.
Any help is appreciated.
Make sure that you're using Publisher ID and not App ID
Publisher ID is the unique identifier for your AdMob account.
Looks something like this pub-7100389293873601
App ID is the unique ID assigned to your app. It looks something like this ca-app-pub-7100382293173983~6849306728.
You can have multiple App IDs (for each app) but you can only have one Publisher ID for your account.
You can find your publisher ID in you AdMob Settings:
Or make sure you pasted it correctly.
Hope this helps!
The Admob account I used was completely new and the "Could not parse Event FE preflight response" was displayed repeatedly. Only when I tried it with an older account it worked. I think you have to wait a bit for verification.
or
Another thing to try is add your payment information to your Admob account
like described in this answer https://stackoverflow.com/a/61423243/8779275 and also check the other points there.

Register a New User with the Mobile SDK for Android on AWS Cognito

Im trying to develop a sing up for AWS Cognito in Android. I just checked the official doc but in the Register a New User section there is only the sample for using SignUpHandler.
Checking other sections, for example Using the JavaScript SDK there is a clear sample using
userPool.signUp('username', 'password', attributeList, null, function(err, result)
Im trying to implement this aproach transpolating the javascript example. But I was wondering if there is any complete sample of sign up for Android?
Thanks in advance!!
The handler you noticed is a parameter for the call to sign up, much like 'function(err, result) in the JS example. Take a look at this part of the docs, it shows how to use that handler. From the example you screenshotted, it might look like this:
userPool.signUpInBackground(userId, password, userAttributes, null, handler);
Here is a complete sample using the link sugested by Jeff:
CognitoUserAttributes attributes = new CognitoUserAttributes();
attributes.addAttribute("phone_number","+15555555555");
attributes.addAttribute("email","email#mydomain.com");
cognitoUserPool.signUp('username', 'password', attributes, null, new SignUpHandler() {
#Override
public void onSuccess(CognitoUser cognitoUser, boolean b, CognitoUserCodeDeliveryDetails cognitoUserCodeDeliveryDetails) {
// If the sign up was successful, "user" is a CognitoUser object of the user who was signed up.
// "codeDeliveryDetails" will contain details about where the confirmation codes will be delivered.
}
#Override
public void onFailure(Exception e) {
// Sign up failed, code check the exception for cause and perform remedial actions.
}
});
The sections Examples of Using User Pools with the Mobile SDK for Android seems to be outdated.
Hope to help somebody else ;)

"Invalid state" on vimeo video upload from other android app

I am trying the upload videos into vimeo from my android application. The video is getting uploaded . But when the Delete request is called in order to get the video id , I am getting a response as "Invalid state". The same piece of code works in Htc X. Is this the issue with video codec format or something else ?
This is my piece of code for delete request
public void vimeoDelete() {
// Vimeo upload step 3
RestClient.mEndPoint.setUrl(APIHandler.VIMEO_BASE_URL);
RestClient.getVimeo().deleteVideo(mCompleteUri.substring(1), new Callback<Response>() {
#Override
public void success(Response response, Response response2) {
Log.i("Delete", "Done");
Log.i("Header", response2.getHeaders().toString());
Log.i("Body", response2.getBody().toString());
List<Header> aHeaders = response2.getHeaders();
for (Header aHeader : aHeaders) {
if (aHeader.getName().equals("Location")) {
mVideoUrlLocation = aHeader.getValue();
}
}
Log.i("Location", mVideoUrlLocation);
mFinalVideoUrl = mVideoUrlLocation.substring(8);
saveDetails();
}
#Override
public void failure(RetrofitError error) {
mProgress.dismiss();
}
});
}
Can anyone suggest a solution to this .
Regards
I just replied to the same issue over on the Vimeo forum - I had the same issue and am simply posting it here as there didn't seem to be a solution on this particular thread.
Also, regarding your post - there's not a lot of information provided in your post. Your delete request is not all that's required - the assumption would be that you created a valid ticket request, uploaded properly, THEN tried the del request you posted.
Vimeo post:
https://vimeo.com/forums/api/topic:278394
My solution:
I solved my version of the issue - I think Vimeo corrected some stuff on their API recently because my code did not have a bug and then suddenly one appeared recently. I would bet they added rate limiting on their API gateway or potentially overwriting existing requests to clean up old requests...
Anyhow, here is my fix:
In order to complete a video upload via "Resumable HTTP PUT uploads" (developer.vimeo.com/api/upload/videos), there are 5 steps.
I do everything but the upload through my PHP backend. I was requesting a ticket through PHP as to not expose some secret info through my modified JS frontend (github.com/websemantics/vimeo-upload) but I had not edited out the ticket request properly through the JS code, so the current bug was probably being triggered on that second invalid request (i.e. overwriting or rate limiting my initial valid request through PHP). Once I bypassed the JS "upload" function properly and jumped right to JS "sendFile_", the upload works properly again.
Hope that helps somebody out there!

View activity list of google plus on android

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.

Facebook Graph API unlike a liked post

I have a method in my app that allows the user to "like" a post in his/her news feed. It's done with a simple graph request using HttpMethod.POST. But when I try to do an "unlike" action using HttpMethod.DELETE, I get an error callback:
02-08 00:35:57.298: I/Detail(2628): {Response: responseCode: 403, graphObject: null, error:
{HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200)
Feed story publishing to other users is disabled for this application}, isFromCache:false}
Now I assume this has something to do with the latest attempt to make all apps that integrate with Facebook use all Facebook looking dialogs and styles, but I could be wrong. Here's the roadmap post that has me suspicious:
Removing ability to post to friends walls via Graph API We will
remove the ability to post to a user's friends' walls via the Graph
API. Specifically, posts against [user_id]/feed where [user_id] is
different from the session user, or stream.publish calls where the
target_id user is different from the session user, will fail. If you
want to allow people to post to their friends' timelines, invoke the
feed dialog. Stories that include friends via user mentions tagging or
action tagging will show up on the friend’s timeline (assuming the
friend approves the tag). For more info, see this blog post.
Any ideas on what I could be doing wrong, or is Facebook just ruining me? Thanks!
EDIT: Here's the code I'm using to run the request.
Request likeRequest = new Request(Utility.fbSession, null, null, null, new Request.Callback() {
#Override
public void onCompleted(Response response) {
String responseString = response.toString();
Log.i("Detail", responseString);
updateDetail();
}
});
HttpMethod nextLikeCall = HttpMethod.DELETE;
likeRequest.setHttpMethod(nextLikeCall);
likeRequest.setGraphPath(itemId+"/likes");
likeRequest.executeAsync();
When you grab the post id from the graph data, it should be in a format like: XXXXX_YYYYY. The XXXXX is simply the users id and YYYYY is the actual post id. What you need to do is extract and use just the YYYYY portion of the post id that graph gives you. so instead of graph.facebook.com/XXXXX_YYYYY/likes.... you want to send graph.facebook.com/YYYYY/likes. This will work with both liking and unliking, you can test in graph explorer first before hacking together a substring extraction method.
Not sure how to extract a section of a string on Android, but I know in Objective-C/iOS, it can be done like this (code not tested, for reference/idea) :
SString *actualPostIdStr; //The String we will put the actual postId in
NSString *oldIdStr = //<the string in format XXXXX_YYYYY>
NSInteger charCount = [oldIdStr length]; //get the length of the original XXXXX_YYYYY string
NSRange fRangeCount = [oldIdStr rangeOfString:#"_"]; //get count of characters to remove (XXXXXX)
if (fRangeCount.location != NSNotFound){
NSInteger startingPos = fRangeCount.location + 1; //get the starting character position of the actual postId
actualPostIdStr = [[oldIdStr substringWithRange:NSMakeRange(startingPos, charCount - startingPos)] copy];
}
Hope this helps.
EDIT:
Ok, so I have been playing around with likes all day... It seems that this method sometimes doesn't work, but it all depends on the type of graph object which you are attempting to like/unlike. For example... plain status posts, this method works perfectly. However, I ran into a problem when trying to like a photo with a message/story post object. It turns out, in the graph data for this type of post object with photo, there is an additional paramter called "object_id", in addition to the plain "id" that is in status post graph data. in this case, with the photo and story post, you need to pass the "object_id", unaltered for successful unliking.
This mess seems like either a bug on FB's end, or they are making changes and disallowing likes/unlikes from graph api & just forgot/haven't to told us yet :) hopefully the former. In the mean time, you're just going to have to use my above answer, but just make sure you test with as many different types of post objects you can find, and use if conditions when a different id (portion of "id"... "object_id"... etc) is required.
Sometimes Daniel McCarthy's method don't work. In this case we need get Graph API request XXX_YYYY, find field object_id and unlike this object_id fid.

Categories

Resources