Facebook Posting on page's wall instead of user's wall - facebook-graph-api

I am using oauth to get offline access token for facebook.
With user (wall) access token, image/text is posted on wall which is right.
But when I use page access token to post some thing on Page than it is not posting on page instead it is posting on user's wall.
Can anyone help me please...

Do it like this. It will work. Replace pageID with your own pageID at which u want to post.
NSMutableDictionary *variablesForEvent=[NSMutableDictionary dictionaryWithCapacity:1];
[variablesForEvent setObject:#"my message" forKey:#"message"];
NSString *postToFBEventRequest = [NSString stringWithFormat:#"%#/feed",#"pageID"];
[FBRequestConnection startWithGraphPath:postToFBEventRequest
parameters:variablesForEvent
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
}];

Related

Why is the accesstoken not set by PFFacebookUtils logInInBackgroundWithReadPermissions method?

For reference: I am using the latest Facebook IOS SDK v4 and the latest Parse v1.7.4 and ParseFacebookUtilsV4 SDK.
So I am using PFFacebookUtils loginInBackgroundWithReadPermissions:block: method to have the user login with Facebook credentials and create a PFUser with those credentials.
And then proceeded to make a facebook graph request with FBSDKGraphRequest which from what i read, assumes a valid token has been set (there is no passing of a token parameter to it).
But the facebook graph request failed, and in tracing the issue, I noticed that the "access token" is never set by the loginInBackgroudnWithReadPermissions method. What this method only does is to create a PFUser and a Session instance in Parse, and store there the session token string, but it does not set the currentAccessToken . When I do a [[FBSDKAccessToken currentAccessToken] tokenString] call within the block, I get (null). But if I read the "token string" from the PFSession class I get the "token string" store in the Session class instance in Parse.
See the code below:
- (IBAction)fbLoginAction:(id)sender {
// Set permissions required from the facebook user account
NSArray *permissionsArray = #[ #"email", #"user_friends"];
// Login PFUser using Facebook
[PFFacebookUtils logInInBackgroundWithReadPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
if (!user) {
NSLog(#"Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew) {
NSLog(#"User signed up and logged in through Facebook!");
// Check if the current token has been set
NSLog(#"self.myCurrentToken string = %#", [[FBSDKAccessToken currentAccessToken] tokenString]); // returns (null)
// Get the token string from the PFSession
[PFSession getCurrentSessionInBackgroundWithBlock:^(PFSession *session, NSError *error) {
NSString *tokenString = session.sessionToken;
NSLog(#"Session token = %#", tokenString);
}];
}
And here is the debug console output
So I am not sure what is happening.
IF the PFSession token is set to something shouldn't the FBSDKAccessToken currentAccessToken not be returning this same PFsession token?
And if I were to set the accessToken manually, how can I convert the tokenstring that is stored in Parse to an FBSDKAccessToken instance? There seems to be no method to do this?
thanks
This is happening because you need to add the following code to the bottom of AppDelegate didFinishLaunchingWithOptions :
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
By adding the code, your currentAccessToken will no longer be nil and you can make requests to FB right away.
FYI, I was able to discover the acccessToken was nil because I got the following error every time I tried to use FBSDKGraphRequest. So if anyone else gets the error below, make sure your accessToken is not nil even after you log in!
{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}
#jhk:
Yes. I got an explanation from Facebook support. Login in through Parse is a two step process. First step, is the authorization step, where the user authenticates with Facebook. It switches to Facebook app, and the app receives Facebook access token when it completes successfully. And the second step is , the app authenticates with Parse (i.e your app) using the Facebook token. If it matches existing user/session, you are logged in successfully. However, I was deleting the PFSession manually from the parse backend, while testing every single time I tried to login, so that invalidated the session stored in the backend, and after the 1st step, when the app gets authorized and gets the accesstoken, the system realizes that the local session doesn't match the parsed stored session and invalidated the accesstoken, it sets it to nil. That is why I am seeing the token being set to nil.

Jsoup captcha login with cookie

I have been trying to develop a small application that gets captcha from my academics page, displays it to the user, the user enters captcha and the program should display details. However, I am stuck at login page itself. I used jsoup to get the cookie,save captcha to a folder, submit captcha along with form data, using the previous cookie. But I get the same login page again. Please help!
This is the get request. Website url https://academics.vit.ac.in/parent/parent_login.asp
Response res = Jsoup.connect(webSiteURL).method(Method.GET).execute();
Map<String,String> cook = res.cookies();
String sessionid = res.cookie("ASPSESSIONIDSQHDAQRQ");
After getting the captcha, this is the post request.
Response login = Jsoup.connect(webSiteURL)
.userAgent("Mozilla/5.0")
.cookie("ASPSESSIONIDSQHDAQRQ", sessionid).
data("message","Enter Verification Code of 6 characters exactly as shown.")
.data("vrfcd",captcha).data("wdpswd","somedata").data("wdregno","somedata")
.method(Method.POST).execute();
System.out.println(login.parse());
When I tried this
System.out.println(login.cookies());
The value is null, is that a clue?? Help me out!! Thanks!!
Are you sure you are retrieving the captcha using the cookie too?. Please check that. I mean, you can download the captcha with something like:
Response res1 = Jsoup.connect("https://academics.vit.ac.in/parent/captcha.asp")
.cookie("ASPSESSIONIDSQHDAQRQ", sessionid)
.ignoreContentType(true)
.method(Method.GET).timeout(30000).execute();
Then be sure that in the login post you are using the correct url, that is:
https://academics.vit.ac.in/parent/parent_login_submit.asp
Then it should work fine.
Hope it helps.

Share multiple videos on one page onto facebook page wall

I'm using Facebook C# SDK to post on fan page wall. (I created FBApp ext...) and using FB connect (Javascript) to user login, with this scope - "publish_actions,manage_pages,publish_stream". after user login i got an access_token to post on the page.
I have a page, and on the page settings "Everyone can add photos and videos to Testpage's timeline" is checked.
I can post message and picture, but when i tried to post a video (Youtube URL), it's appears on section "Recent Posts by Others on Testpage". When the Everyone can add photos and videos to Testpage's timeline" is not checked, I don't see any post.
To post a video on page, I must enabled "Everyone can add photos and videos to Testpage's timeline"?
When i success to post a video, Why the video appears on "Recent Posts by Others on Testpage"?
My Facebook user is admin on the page and I'm login with this user.
Thank's
To do this, you need to get the access token from the user accounts, and not from the FB.Login.
string getPagesTokensUrl = string.Format(#"https://graph.facebook.com/me/accounts?access_token={0}",accessToken);
using (WebClient wc = new WebClient())
{
var pagesTokens = wc.DownloadString(getPagesTokensUrl);
JObject o = JObject.Parse(pagesTokens);
for (int i = 0; i < o["data"].Count(); i++)
{
if (o["data"][i]["id"].ToString() == ConfigurationManager.AppSettings["YOUR PAGE ID"])
{
return o["data"][i]["access_token"].ToString();
}
}
}

Posting photo to user's photos offlne using facebook php api

To post a photo to logged in user's photos these are the api function parameters:
$result = $facebook->api('/me/photos/', 'post', $attachment);
I would like to post a photo in offline mode using this:
$result = $facebook->api('/'.$user_id.'/photos/', 'post', $attachment);
But this does not work, because I think user_id is read as a album id.
What is the proper url for posting to user's photos when I have a user id?
Where can I find the list of all these "url"s for different graph actions?
Note:User has granted publish and offline permissions to the app.
As long as the token is active you can use me so $result = $facebook->api('/me/photos/', 'post', $attachment); should still work back when offline_access was possible. Even now with 2 month tokens you can use me, again as long as the access token is valid.

How to properly use app and user tokens with the Facebook Score API on iOS

I'm trying to post a high score to the Facebook Graph API in iOS, but having no luck getting past all the token stuff. I've modified the iOS library to store the app token and the user token and I swap the app token in when making the post to https://graph.facebook.com/{my user id}/scores, but I keep getting an error back about needing a user token. When I swap the user token in, it tells me I need an app token.
I figured it might be something like the user token getting switched back in before the request completed but I have double and triple checked that the request comes back with the app token I received as the access_token post value. According to the debugging I've been doing, I need both a user access token and an app access token.
*After called oauth/access_token*
NSString *tempToken = [[[NSString alloc] initWithData:[request responseText] encoding:NSUTF8StringEncoding] autorelease];
//Response is something like "access_token={APP ID}|{SOME HASHED VALUE}"
[fb setAppAccessToken:[tempToken substringFromIndex:13]];
[fb setAccessToken:[fb appAccessToken]];
NSMutableDictionary *scoreParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:#"20", #"score", nil];
[fb requestWithGraphPath:#"{MY USER ID}/scores" andParams:scoreParams andHttpMethod:#"POST" andDelegate:self];
[fb setAccessToken:[fb userAccessToken]];
With USER ACCESS TOKEN "(#15) This method must be called with an app access_token."
With APP ACCESS TOKEN "A user access token is required to request this resource."
I'm also using publish_actions as a permission.