Share video to Facebook via Graph iOS SDK - ios

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

Related

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. :-)

google places for iOS empty referrer

I have been working completely fine with google maps sdk and the places api. yesterday my code was running perfectly fine. but woke up this morning, made some modifications then ran into a compiling snowball of issues which seems like an easy fix but have spent a couple hours trying to figure out what is going on. I am trying to develop an iPhone application.
I have gone back, created a "new project" in the developer console
regenerated a new iOS key.
entered the new bundle ID in the info.plist
entered the new api key in the delegate file and within the search parameter of the url.
i am using alamofire and swiftyjson to parse the data
but still get the same issue.
2016-01-28 13:15:55.683 Google Maps SDK for iOS version: 1.11.21919.0
{
"error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address "myIPAddress", with empty referer",
"results" : [
],
"status" : "REQUEST_DENIED",
"html_attributions" : [
]
}
func downloadRestaurantDetails(completed: DownloadComplete) {
let URL_Search = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?"
let API_iOSKey = "My iOS API Key"
let urlString = "\(URL_Search)location=\(clLatitude),\(clLongitude)&radius=\(searchRadius)&types=\(searchType)&key=\(API_iOSKey)"
let url = NSURL(string: urlString)!
Alamofire.request(.GET,url).responseJSON { (response) -> Void in
if let value = response.result.value {
let json = JSON(value)
print(json)
if let results = json["results"].array {
for result in results {
if let placeIDs = result["place_id"].string {
self.placeIDArray.append(placeIDs)
}
}
}
}
completed()
}
}
You've misconfigured your API key.
First, your issue is with the Google Places API Web Service, which can only be used with Server keys not iOS keys. You're calling the web service (https://maps.googleapis.com/maps/place/...) so iOS keys and bundleID key restrictions aren't going to work here (and are likely to confuse things).
So you need to follow the instructions at https://developers.google.com/places/web-service/get-api-key, and make a Server Key with "Google Places API Web Service" enabled in the Developers Console (not the same as "Google Places API for iOS"). To be useful on phones you probably don't want to set any IP restrictions (and IP restrictions are the only kind possible for Server keys). Use that key in your HTTP requests.
Anything else will get REQUEST_DENIED errors.
This error sounds like you have generated a browser key rather than an iOS key. Try generating an iOS key in the Cloud Console and make sure that your bundle ID is whitelisted.

get user likes from FBSDK graph Api (V 2.5)

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.

Facebook get number of likes on custom object without login

I am using og.likes to like custom object from my app, with the help of Facebook-iOS sdks. I am able to like object and also read the like.
Now I want to know if there is any way in graph API that, I can show total number of likes on an object to a user who is not logged in to our app via Facebook ? i.e without access token
As per FB developer docs:-
https://developers.facebook.com/docs/graph-api/reference/v2.3/object/likes
It is mentioned that you need the same permissions required to view the parent object are required to view likes on that object, means an user access token with read_stream permission is required.
NOTE:
But if a user want to get the no of likes for Facebook page or profile or object , then it can be easily done by this:-
https://graph.facebook.com/< your object id>/
Then you will receive json response with Like Count:-
{
"id": "12345",
"link": "http://www.facebook.com/pages/MY iOS Page/102445859460201",
"likes": 150,
"type": "page"
}
Code:-
let url = NSURL(string: "http://graph.facebook.com/"+ObjectID)
let urlRequest = NSURLRequest(URL: url!)
NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (response:NSURLResponse!, data:NSData!, error:NSError!) -> Void in
// Fetch the data
var jsonDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary
let likesCount = jsonDictionary["likes"] as? String
}
Got Response from Facebook Team :
Since Graph API v2.0, all requests to the API require an access token.
You can proxy this request through a web-server and use your app
access token for example.
You could as well make the request from your app by shipping your app
access token with the app, but I highly advise against this as the app
token should be kept secret.
Please note that the SDK does not support using the app access token
for security reasons. So you have to write your own networking code to
fetch this data.
I got the solution from
How to get Likes Count when searching Facebook Graph API with search=xxx
Here in this link it's not the exact solution but i have tried my way and unfortunately it worked for me, and i am quite satisfied with it, still using it in my application.
https://graph.facebook.com/v2.1/{Object-id}?fields=likes.summary(true)
You will need an access token, no need to login any user, you can generate an APP Access token to get that info .
jQuery.get("https://graph.facebook.com/oauth/access_token", {
'grant_type': "client_credentials",
'client_id': "000000000000000",
'client_secret': "0000000000000000000000000000000000"
}, function (data) {
// data is the app access token you will need for calling graph api
});
Thats more complicated but solves the necessity to login the user to get public informations from the graph .

How do I use the YouTube Data API in my iOS app? I get "Access not configured" error on each request

I want to use the YouTube Data API to get the links to thumbnails for a specific YouTube video in my iOS app. I went to Google Developers Console and created a new project.
For that project I then went to "APIs" and removed the default APIs it enables for me and added the YouTube Data API. I then went to credentials, created a Public Key (as I don't need the user to log in or anything, just getting the thumbnail URLs) as iOS, which gave me an API key. I added the Bundle Identifier for my project under Allowed Applications.
Now in my app I tried the following code:
let test = NSURLSession.sharedSession().dataTaskWithURL(NSURL(string: "https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=*MYKEYHERE*&part=snippet,contentDetails,statistics,status")!, completionHandler: { (data, response, error) -> Void in
let json = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil)
println("JSON: \(json)")
})
But it prints out the error:
JSON: Optional({
error = {
code = 403;
errors = (
{
domain = usageLimits;
message = "Access Not Configured. Please use Google Developers Console to activate the API for your project.";
reason = accessNotConfigured;
}
);
message = "Access Not Configured. Please use Google Developers Console to activate the API for your project.";
};
})
What exactly am I doing wrong?
There is a known problem about Bundle id in the console. If you can just remove that restriction, it should just work fine.
You can track the original issue from here: https://code.google.com/p/gdata-issues/issues/detail?id=5770
Here's what you need, YouTube has a service API via web to consult this types of things. I'm using this URL to consult all videos from a user (getting every videos: URL, Thumbnail, views, duration, etc). I'm sure you'll find thumbnails for a particular video. Its a JSON response so you'll have to take a good look to the structure but can't get simpler than this.
http://gdata.youtube.com/feeds/api/users/USER_NAME/uploads?v=2&alt=json&#&start-index=1&max-results=10

Resources