iOS Swift: Can't create pinterest pin with PinterestSDK - ios

I am experiencing issue while trying to create pin with Pinterest SDK, I use this code:
PDKClient.sharedInstance().createPin(with: imageToShare, link: URL.init(string: "https://someUrl"), onBoard: "MyBoard", description: "",
progress: { (percent) in
}, withSuccess: { (response) in
print("Success")
}) { (error) in
if let error = error {
print(error)
}
}
And I receive this particular response:
Error Domain=com.alamofire.error.serialization.response Code=-1011
"Request failed: not found (404)" UserInfo
{NSLocalizedDescription=Request failed: not found (404),
NSErrorFailingURLKey=https://api.pinterest.com/v1/pins/
User is logged in into Pinterest application, just before calling this line of code, I am able to successfully create board with name MyBoard via the same API, but I am stuck within creation of the pin.
I tried to create pin with image url (because I thought that maybe it is because of my image), but it outputs the same response.
I am using twitter and facebook sdk within the same code, Info.plist seems allright.
Any clues?

Apparently the problem was, that onBoard actually requires not a board name, but it's identifier. So when you create pin board programatically -- (PDKClient.sharedInstance().createBoard) you should fetch and save it's identifier, which can be fetched in response (response.board().identifier).
I was stuck within this problem for the past 1.5 hours and figured it out just after posting the question :) I think it can be useful for someone else, because official SDK wiki is not very informative and git repository is quite dead too.

Related

Getting error of "Publisher identifiers not found" when I enable "debugGeography" in AdMob

I am trying to test my GDPR compliance code and trying to display the consent form for AdMob but I get this error:
Consent info update failed. Error: Error Domain=Consent Code=1
"Response error. Publisher identifiers not found: ca-app-pub-0123456789012345"
I have triple checked, my publisherID is correct, it is something like "pub-0123456789012345".
When I check my AdMob account status I see that
"Your account is active and in good standing."
I have followed the directions of Google to receive user consent for personalized ads. I am in the USA, so use this line:
PACConsentInformation.sharedInstance.debugGeography = .EEA
When I disable this line, I don't get the error above anymore, but the error below:
Error loading form: Error: request is not in EEA or unknown.
I have tried to use this line instead but nothing changed:
PACConsentInformation.sharedInstance.debugGeography = PACDebugGeography.EEA
My only guess is that for the reason that my AdMob account is USA based, I get "publisherID not found" error when I enable ".EEA". But how can I do the testing if my guess is true?
I am doing the testing both on simulator and on the phone. I could not manage to display the consent form anywhere.
The code I am using is below:
// advertiseIDOfPhone and publisherID are constants defined elsewhere
PACConsentInformation.sharedInstance.debugIdentifiers = [advertiseIDOfPhone]
PACConsentInformation.sharedInstance.debugGeography = .EEA
PACConsentInformation.sharedInstance.requestConsentInfoUpdate(forPublisherIdentifiers: [publisherID])
{(_ error: Error?) -> Void in
if let error = error {
// Consent info update failed.
print("☢️ Consent info update failed. Error: \(error)")
} else {
print("☢️ Consent info updated.")
// Consent info update succeeded. The shared PACConsentInformation
// instance has been updated.
switch PACConsentInformation.sharedInstance.consentStatus {
case .nonPersonalized:
print("☢️ Personalized ads consent NOT given.")
case .personalized:
print("☢️ Personalized ads consent given.")
case .unknown:
print("☢️ Unknown consent.")
guard let privacyUrl = URL(string: "yourWebsiteURL"),
let form = PACConsentForm(applicationPrivacyPolicyURL: privacyUrl) else {
print("incorrect privacy URL.")
return
}
form.shouldOfferPersonalizedAds = true
form.shouldOfferNonPersonalizedAds = true
form.shouldOfferAdFree = true
form.load {(_ error: Error?) -> Void in
print("⚛️ Load complete.")
if let error = error {
// Handle error.
print("⚛️ Error loading form: \(error.localizedDescription)")
} else {
form.present(from: self) { (error, userPrefersAdFree) in
if error != nil {
// Handle error.
} else if userPrefersAdFree {
// User prefers to use a paid version of the app.
//buy the pro Version
}
}
}
}
default:
break
}
print("☢️ isRequestLocationInEEAOrUnknown: \(PACConsentInformation.sharedInstance.isRequestLocationInEEAOrUnknown)")
}
}
Where can be my mistake here? Is the code I am using good?
--
It seems that this is a known bug:
Kindly note that we are aware of this issue, and our Engineering team
is already working on a resolution. Rest assured that we are keeping
an eye out on this, and that we will update you for any news regarding
this issue.
Regards, Ziv Yves Sanchez Mobile Ads SDK Team
I didn't expect a bug from Google in such a fundamental aspect of a big product and unfortunately I have spent hours on this problem trying to find my mistake somewhere...
While they work on a resolution, you can use the Google Test Publisher ID:
pub-3940256099942544
My account gives me the error but I was able to use the test ID to implement and test the Consent SDK. Just make sure you switch back to your ID before you distribute the app.
I got the Same Issue!
This is not our Code's fault. Admob not serving ads.
Go to Admob Console
In Home There is Dialog Box: "Don't serve Until PaymentDetails Entered"
Click the Learn more and create an AdSense account
after that enter payment details
That's all they will serve ads after 24 hours after the account verified
I have the same issue.
Until I updated my settings on https://fundingchoices.google.com.
Go to the webpage, select APP on the left side, go in and activate the app you are using.

iOS Swift: How can we create pin in Pinterest?

I have all the boards of logged in user and using Pinterest api I am able to fetch the pins from given board but Create pins is not working.
I have create Application on Pinterest Developer https://developers.pinterest.com/
As per document , I have added collaborator for authenticated users. Send perfect parameters for create pins after permission api.
I got perfect response in permission api and in boards but getting error in create pin from my application.
Please look below my code:
PDKClient.sharedInstance().createPin(withImageURL: URL.init(string: aImageUrl), link: URL.init(string: "https://www.pinterest.com"), onBoard: myBoardID, description: "Hello All", withSuccess: { (response) in
//print(response)
print("Pinterest sucess")
}, andFailure: { (error) in
print(error as Any)
print("Pinterest Fail")
})
For this api I am always getting 404 or 400 error.
Please help me for that.
Thanks in advance.

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

GooglePlaces API "Response That We Couldn't Understand" Error

Using the standard autocomplete code with a searchbar:
placesClient.autocompleteQuery(searchBar.textField.text!, bounds: nil, filter: filter, callback: {(results, error) -> Void in
if let error = error {
print("Autocomplete error \(error)")
return
}
if let results = results {
for result in results {
print("Result \(result.attributedFullText) with placeID \(result.placeID)")
self.predictions.append(result)
}
}
self.placesTableView.reloadData()
})
Has been working for months and tonight it started reporting this error:
Autocomplete error Error Domain=com.google.places.ErrorDomain Code=-2 "The Places API server returned a response that we couldn't understand. If you believe this error represents a bug, please file a report using the instructions on our community and support page (https://developers.google.com/places/support)."
UserInfo={NSLocalizedFailureReason=The Places API server returned a response that we couldn't understand. If you believe this error represents a bug, please file a report using the instructions on our community and support page (https://developers.google.com/places/support)., NSUnderlyingError=0x600000444380 {Error Domain=com.google.places.server.ErrorDomain Code=-1 "(null)" UserInfo={NSUnderlyingError=0x600000444350 {Error Domain=com.google.HTTPStatus Code=404 "Not Found" UserInfo={NSLocalizedDescription=Not Found}}}}}
Anyone else experiencing this?
Looks like the service is back up. I raised a ticket with Google.
They identified the issue and are resolving it. Mentioned it could take a few hours.
See below:
https://issuetracker.google.com/issues/64280749
https://issuetracker.google.com/issues/64994023
This issue has been filed with Google, Google has identified the bug, and they are currently working on a fix. Issue tracking: https://issuetracker.google.com/issues/64280749
See: why loading places in iOS using google places api causes lookup place id query error?
thank-you: #trishcode

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