I'm trying to get a post from Facebook using the Facebook4J API. It's been working excellently, so far, but I've run into a little problem.
When I use
PostMethods pp = null;
Post post = pp.getPost(postId);
I see problems. If the post ID is something like "592496714151070", this call works absolutely fine, but if I give a post Id like "164204816980264_592496714151070", I get a runtime exception:
RuntimeException in run(): [Ljava.lang.StackTraceElement;#1d944379
The second type of post Id is for a post that is on the wall of a page, so it's the pageId followed by a post Id.
Is there way to fix this, or saving that, a way to get posts from 'others' on a facebook page's wall?
Sam
I'm not sure if I understood your question completely. However, you don't have to access all posts explicitly. You can crawl them altogether using a simple generic facebook4j client as described here:
Getting posts from a page using Facebook4j api
Related
I am working on an app that will help me log in the website and view data that I need. While I have no trouble with making sure that I parse that data and work with it properly, I did face an issue with logging into the website. I tried sending POST request, yet that didn't really work for some reason so I started looking more closely into how POST request to that website is sent in the browser and here is what I got:
Picture
I also asked a guy who developed that website and he said that I should use two cookies with "ulogin" and "upassword" for my log in. I tried using JSOUP as shown right here: https://jsoup.org/cookbook/input/load-document-from-url
I used .cookies("upassword", "10101010"), yet it didn't work so it makes me think that there is a bit more to it than just writing a simple line a post request.
Please, can someone explain to me how do I use cookies to log into website or at least point me in the direction where I can learn that, because I am so close to making that app happen and I will be able to proceed further with it's development, but it's just this one step that I am really being stuck with.
Here is an additional picture with Response and Request Headers from the Firefox. Picture
I managed to get it working a long time, yet didn't post an answer. So, here we go.
Cookies are just simple Headers, therefore you should treat them as such. In my case, with the use of HttpURLConnection, here is a piece of working code:
Note: My original request is for Java, however, I have since moved to Kotlin, so this solution uses Kotlin and this function is a "suspend" function which means that it is designed to be used with Kotlin Couroutines.
suspend fun httpRequest(): String {
val conn: HttpURLConnection = url_profile.openConnection() as HttpURLConnection
conn.requestMethod = "POST"
conn.doOutput = true
conn.doInput = true
conn.setRequestProperty(
"Cookie",
"YOUR COOKIE DATA"
)
val input: BufferedReader = BufferedReader(InputStreamReader(conn.inputStream))
return input.readText()
}
I've been familiarizing myself with Play Framework in Java. I took on a fairly simple change request for an application, but I don't think I fully understand how to go about fixing it. The request is to repopulate the email field after a failed login attempt. I realize it's probably a pretty simple fix but I wasn't able to find a solution for this particular situation. Here's what I've found
Routes file:
#Sessions
GET /logout #femr.ui.controllers.SessionsController.delete()
POST /login/reset #femr.ui.controllers.SessionsController.editPasswordPost()
POST /login #femr.ui.controllers.SessionsController.createPost()
GET /login #femr.ui.controllers.SessionsController.createGet()
Code Snippit within SessionsController.java (Commented lines are my attempted fix):
public Result createPost() {
final Form<CreateViewModel> createViewModelForm = formFactory.form(CreateViewModel.class);
CreateViewModel viewModel = createViewModelForm.bindFromRequest().get();
ServiceResponse<CurrentUser> response = sessionsService.createSession(viewModel.getEmail(), viewModel.getPassword(), request().remoteAddress());
if (response.hasErrors()) {
//CreateViewModel emailModel = new CreateViewModel();
//emailModel.setEmail(viewModel.getEmail());
//createViewModelForm.fill(emailModel);
return ok(create.render(createViewModelForm));
}
Here I'm attempting to fill in the email field before rendering the form, but it didn't quite do the trick. I looked online and saw something about doing an explicit render but that didn't quite work for me either.
The form I found is create.scala.html and I believe the solution may involve using javascript or something in this, but I'd like to handle it just in the SessionController in Java if possible.
Suggestions welcome!
I am trying to use the Instagram-API to subscribe to a user so that when that user posts anything on Instagram, then my app will receive a POST. I have set up the app in the sandbox, defined the callback URIs, added my user to the Sandbox, then called the following url to register a subscription;
https://api.instagram.com/v1/subscriptions?client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET&object=user&user_id=jonlees1234&aspect=media&verify_token=1234567890&callback_url=https://instagram.pulselive.com/SubscriptionCallback
The part of that URL that I am unclear about is the following;
&object=user&user_id=jonlees1234&aspect=media
I have a GET and POST method on my Callback Url so that when the SubscriptionValidation GET is called the hub.challenge is echoed. I have tested this and it works. However, the response I get from the above URL is as follows;
{"meta":{"code":200},"data":[]}
This indicates that all is working, but that there are no subscriptions when I run the list of subscriptions api call.
What could I be missing?
Ok, I finally I found the answer.
https://api.instagram.com/v1/subscriptions?client_id=MY_CLIENT_ID&client_secret=MY_CLIENT_SECRET&object=user&id=3111490094&aspect=media&verify_token=THE_USERS_ACCESS_TOKEN&callback_url=http://instagram.pulselive.com/SubscriptionCallback
The KEY issue was that I was using the username and I SHOULD have been using the user id, as follows;
&object=user&id=1234567890&aspect=media
All working now.
My problem is I get error while trying to get request token from Yahoo. The error says Im missing oauth_callback parameter and yes I miss it because I dont need it. Ive read I need to set it to "oob" value if I dont want to use it(desktop app). And I did that but to no avail. If I set it to null the same happens. Im using OAuth for java: http://oauth.googlecode.com/svn/code/java/core/
OAuthServiceProvider serviceProvider = new OAuthServiceProvider("https://api.login.yahoo.com/oauth/v2/get_request_token",
"https://api.login.yahoo.com/oauth/v2/request_auth",
"https://api.login.yahoo.com/oauth/v2/get_token");
OAuthConsumer consumer = new OAuthConsumer("oob", consumerKey, consumerSecret, serviceProvider);
OAuthAccessor accessor = new OAuthAccessor(consumer);
OAuthClient client = new OAuthClient(new HttpClient4());
OAuthMessage response = client.getRequestTokenResponse(accessor, OAuthMessage.POST, null);
System.out.println(response.getBodyAsStream());
Have you tried using Scribe?
I also had problems with OAuth java libs so I developed that one. It's pretty much cross provider and better documented than the one you're using.
If it does not work with Yahoo you can easily extend it creating your own Provider
Hope that helps!
there is a problem in the java OAuthMassage class, I resolved it by adding to addRequiredParameters method thie line
if (pMap.get(OAuth.OAUTH_CALLBACK) == null) {
addParameter(OAuth.OAUTH_CALLBACK, consumer.callbackURL);
}
if you still have this problem I can help you: rbouadjenek#gmail.com
I haven't used that library, but it looks like it isn't properly handling the callback URL. Since OAuth 1.0a (http://oauth.net/advisories/2009-1/ and http://oauth.net/core/1.0a/), the callback URL needs to be sent in the first call to get the request token (not in the client-side call to authorise it), and it seems that this library hasn't been updated to do this (at least from looking at the code). I assume that Yahoo requires the parameter to be there.
Not sure if the original problem was ever solved, but wanted to point to a new Java OAuth SDK that Yahoo released last week:
http://developer.yahoo.net/blog/archives/2010/07/yos_sdk_for_java.html
Developers trying to access Yahoo's services via OAuth with Java may find parts of this SDK helpful.
Hi I want to publsh a post on user's wall but am getting this "permission error" error code 200 when trying to use stream.publish method of facebook api...i hve requested for extended permissions as:
http://m.facebook.com/login.php?api_key="+API_KEY&....&req_perms=read_stream,publish_stream,offline_access
but when i make call to the method stream.publish i am getting this permission error..it seems that req_perms in above url is simply getting ignored..
i am passing "method(stream.publish)","api_key","message","session_key","v","sig" as parametres to url http://api.facebook.com/restserver.php?
will be greatful if anyone helps meout in this problem or provide me with proper steps for publishing a post on user's wall...the application is being developed on blackbery platform..
I don't think you can request permissions from login.php. Instead check out prompt_permissions.php
http://wiki.developers.facebook.com/index.php/Authorization_and_Authentication_for_Desktop_Applications
Can you check to see if you are getting a valid session from facebook before trying stream.publish? If you are getting the offline_access extended permission, you will have a session object that has expires=0.
You can also try called the users.hasAppPermission API methods to verify you got the permissions.
Are you just making POSTs directly to http://api.facebook.com/restserver.php ? Are you including the request data in the POST body? You also should include a Content-Type: header of application/x-www-form-urlencoded in your headers.
I think it can be tricky to make direct calls to the restserver.php. Is there a client library you can use, like the Javascript client library?