get user likes from FBSDK graph Api (V 2.5) - ios

I am trying to retrieve all pages a user has liked on Facebook in my app. Taking from the Graph API, here is my code:
let request3 = FBSDKGraphRequest(graphPath: "/me/likes", parameters: ["fields": "id,name,picture, user_likes"])
request3.startWithCompletionHandler({ (connection3, result3, erreur3) -> Void in
if erreur3 == nil {
print(result3)
}
else {
print(erreur3)
}
})
this code yields this:
{
data = (
);
}
I also tried "me/likes", and it gave me the same empty data set. I tried some of the answers here Facebook Graph API - likes returns me an empty set as well but none of those worked.
I have the "user_likes" permission, and I have a valid AccessToken as well.
Also, I have set my Facebook likes to public, so I know they aren't being hidden because of privacy settings. Any idea how to get the user likes?
thanks

See this is screenshot i got data ..
if you have don't permission on graph explore then you don't get any result..
in a development you add permission on graph explorer then after when you live your app you need to submit your app for permission.
if you have any query then tell me i will help you.

Related

Share video to Facebook via Graph iOS SDK

I try to upload video to Facebook using Graph API.
But always see error message
(#100) No permission to publish the video.
Facebook app has Development mode. I created test user there. My role is admin. FB access token is valid.
Here my code here:
private func upload(url: URL) {
guard let data = try? Data(contentsOf: url) else { return }
let connection = GraphRequestConnection()
connection.delegate = self
var items: [String: Any] = [:]
items["title"] = "Test title from api"
items["\(url.absoluteString)"] = data
let keys = ["value" : "EVERYONE"]
items["privacy"] = keys
let request = GraphRequest(graphPath: "me/videos", parameters: items, httpMethod: .post)
connection.add(request) { reqconnection, anyInfo, error in
print(reqconnection)
print(anyInfo)
print(error)
}
connection.start()
}
I saw a lot of questions about it, but mostly they are too old and don't work for me.
Share video to FB
From thread FB Developers here - the same error, but they didn't find solution
Also check this docs - doesn't work
Also I'm a bit confused what docs are right for post video in Facebook.
Because in docs I see
The Video API allows you to publish Videos on Pages and Groups. Publishing on Users is not supported.
but also in another docs see Graph API with path me/videos. So it confused me a bit.
What docs are correct for my case:
here
here
From docs I see that
Your app should manage permissions as follows:
Graph API Requests - Before you send Graph API requests, you should check for necessary permissions and request them if needed.
Where can I find permission publish_actions?
Please help to figure out how to fix that.
I only can upload via ShareDialog. Like here and docs here

Sharing to specific Facebook page using Swift SDK GraphSharer

In my iOS app I'm trying to use the Facebook Swift SDK so that a user can post a URL to a specific Facebook page that they manage.
I've managed to get the following code working - but it only shares the post to my home timeline:
let content = LinkShareContent(url: URL(string: urlString)!)
let sharer = GraphSharer(content: content)
sharer.failsOnInvalidData = true
sharer.completion = {
(result) in
print(result)
}
do {
try sharer.share()
}
catch (let error) {
print(error.localizedDescription)
}
I believe that I need to use the graphNode property to specify the destination page and that the correct format is as follows:
sharer.graphNode = "/\(pageId)"
However, when I set this property before posting, I am getting an error:
failed(Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL"
I've tried a dozen different formats to specify the node but they all return the same error and I can't find any working examples.
I managed to resolved this issue. It turns out that the graphNode path above is correct but I was looking in the wrong place due to the error message I was getting. Instead I just needed to specify the accessToken parameter.
graphSharer.accesstoken = myPageAccessToken
Note: The access token is not the user's current access token, but an access token you can retrieve when calling the /me/accounts API.
var graphPath = "/me/accounts"
I also then had an issue posting to the page because I had only requested the publish_actions permission. From the documentation, this appears to be suitable but it only worked where I requested further permissions as follows:
loginManager.logIn(withPublishPermissions: ["publish_actions",
"manage_pages", "publish_pages"], ...
Hopefully this will be of use to someone in future. :-)

AWS Cognito check and get users

I'm building an iOS App that is using Amazon MobileHub. Currently it's associated with Cognito and the sign up and sign in flow works great.
What I'm trying to achieve is for one user to be able to add another user as a friend so to speak. To make that possible, I need to check if a user with a specific username exists and if it does, get some attributes such as the name of that target user.
I've tried to use the get user > get details function but it gives me an error Authentication delegate not set.
Here's the code I used:
var pool: AWSCognitoIdentityUserPool?
let user = pool?.getUser(usernameField.text!)
self.pool = AWSCognitoIdentityUserPool.init(forKey: AWSCognitoUserPoolsSignInProviderKey)
user?.getDetails().continueWith { (task: AWSTask<AWSCognitoIdentityUserGetDetailsResponse>) -> Any? in
if let error = task.error as NSError? {
print("ERROR: " + error.localizedDescription)
return ""
}
print(task.result)
return ""
}
An approach I thought of was to store the username and the attributes I want to access to DynamoDB and then access it there but that will just create double unnecessary entries.
The issue you'll run into is that user attributes aren't publicly visible. Only the user who has signed in can call GetUser. If it's a back end process, you could do this via the AdminGetUser operation, but this looks client side so I wouldn't recommend that. The only real way around this would be to do what you suggested at the bottom of your post, ultimately.

Graph Path and Parameters for getting facebook friends list in Swift

I'm using the below code to get the friends list,
let fbRequest = FBSDKGraphRequest(graphPath:"/me/friends", parameters:["fields": "friendlists"]);
fbRequest.startWithCompletionHandler { (connection : FBSDKGraphRequestConnection!, result : AnyObject!, error : NSError!) -> Void in
if error == nil {
print("Friends are : \(result)")
} else {
print("Error Getting Friends \(error)");
}
}
It's always returning empty array.
OutPut:
Friends are : {
data = (
);
}
If I try sending a simple call to /me/friends, FBSDKGraphRequest(graphPath:"/me/friends", parameters:nil) an error logged as below,
FBSDKLog: starting with Graph API v2.4, GET requests for //me/friends should contain an explicit "fields" parameter.
So I referred this answer for the above Parameters.
I authorized the app with two facebook users, both of them are friends in facebook, But I can't see their details in the response.
Still, empty array is returning.
Anyone please check whether the graph path and parameters I mentioned in the code is correct.
The privacy settings in the facebook account for friends list is public.
There is a difference between "friends" and "friendlists". What you want to get is the list of "friends", not the "friendlists". You donĀ“t need the "fields" parameter for that, a simple call to /me/friends is enough.
That being said, you can only get friends who authorized your App too, so if none of your friends authorized your App, you will get an empty array. Of course you need to authorize with the user_friends permission, and your friends must authorize your App with that permission too.
You can get only authorized friends with your application.
Only friends who installed this app are returned in API v2.0 and higher. total_count in summary represents the total number of friends, including those who haven't installed the app.
Check this link for deatiled information.
You can get only count of friends linked to your account, but you can not get any other detail of friends without permission.

Facebook Open Graph Stories in iOS successfully creates an object but cannot post to fb timeline

I am trying to implement Open Graph Stories in iOS of facebook as shown in here: https://developers.facebook.com/docs/sharing/opengraph/ios#custom
I need to post it to facebook via custom interface, not with facebook share dialog.
So far, I can successfully create an open graph object per request, it does not return any error but does not post it to Facebook timeline neither. All I see in xcode is: postId: 113077439054125, completionGesture: post
I am not sure what goes wrong.
Here is my code snippet:
var photo = FBSDKSharePhoto(imageURL: imgUrl, userGenerated: false)
var properties : [NSObject : AnyObject] = [
"og:type" : "video.movie",
"og:title" : "TEST TITLE",
"og:image" : "https://www.facebook.com/images/fb_icon_325x325.png",
"fb:explicitly_shared" : true]
var object = FBSDKShareOpenGraphObject(properties: properties)
var shareApi = FBSDKShareAPI()
var action = FBSDKShareOpenGraphAction(type: "MYNAMESPACE:myAction", object: object, key: "movie")
var content = FBSDKShareOpenGraphContent()
content.action = action
content.previewPropertyName = "movie"
shareApi.delegate = self
shareApi.shareContent = content
shareApi.share()
I've been struggling with it for some time by now. Any help would be appreciated.
Thanks.
You should have solved it. If not, did you get the token for publish_actions permission?
This is how you can get it:
Go to Graph API Explorer.
Select your application.
Click "Get User Access Token".
Select "Extended Permissions" then "publish_actions".
Click "Get Access Token".
That's it.
You have to get your app approved by Facebook in order to gain publish_actions right? When you login to Facebook what are the different access permissions that it shows. Usually you will get a line in the Facebook permission page that says this app does not let you post to timeline or something like that.
What you can try is to create Test Users and use it to login. Test users get all the permissions that you ask for since they are separate from normal users. Note that these are not same as Testers which are still normal FB accounts.
Try using Test Users and once your app is ready to go live, send it to Facebook from the app dashboard and once approved by them you should be good to go live.

Resources