I develop a mobile application with HTML5 + Cordova (Phonegap) using Facebook Javascript SDK for iOs and Android.
I implement it like this :
FB.api(
{
method: 'fql.query',
query: 'SELECT uid, name, birthday_date FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())'
},
function(response) {
console.log(response);
// some code
});
It worked for several months on Android & iOs, until yesterday, on Android.
An error occurs when the call to the api is doing and the callback function is not called.
Here is the error from LogCat in eclipse :
02-26 12:27:10.526: W/chromium(22379):
external/chromium/net/spdy/spdy_session.cc:1246:
[0226/122710:WARNING:spdy_session.cc(1246)] Could not parse Spdy
Control Frame Header. 02-26 12:27:10.526: D/chromium(22379): Unknown
chromium error: -337 02-26 12:27:10.526: W/chromium(22379):
external/chromium/net/spdy/spdy_session.cc:1058:
[0226/122710:WARNING:spdy_session.cc(1058)] Received data frame for
invalid stream 1 02-26 12:27:10.526: W/chromium(22379):
external/chromium/net/spdy/spdy_session.cc:1058:
[0226/122710:WARNING:spdy_session.cc(1058)] Received data frame for
invalid stream 1
It seems to be an error of the android browser Chromium when calling query Facebook (which using the protocol spdy)
Anyone has an idea ?
Thank you !
Seeing the same thing!
/chromium( 1942): external/chromium/net/spdy/spdy_session.cc:1246: [0307/015242:WARNING:spdy_session.cc(1246)] Could not parse Spdy Control Frame Header.
W/chromium( 1942): external/chromium/net/spdy/spdy_session.cc:1058: [0307/015242:WARNING:spdy_session.cc(1058)] Received data frame for invalid stream 21
W/chromium( 1942): external/chromium/net/spdy/spdy_session.cc:1058: [0307/015242:WARNING:spdy_session.cc(1058)] Received data frame for invalid stream 21
D/chromium( 1942): Unknown chromium error: -337
Found news about FB implementing SPDY without much news:
http://zoompf.com/2013/03/facebook-adds-spdy-support
Surprised we're not seeing more issues around.
I have the same problem with the similar code under identical
circumstances, PhoneGap, Android
The solution is to switch to Graph
API. Using Graphi API the same call will be
FB.api('/me/friends', { fields: 'id, name, gender, username' }, function (response) { ... });
There are a number of caveats that might
not be applicable to you but were applicable to me
The fields named differently. “sex” is now “gender”, for example Graph API does not
have direct analog of is_app_user field. If you add it to the list
of fields, you’ll get an error. There is a workaround asking
specifically for the users who installed the app
There is paging
implemented in response. So the response is structured a bit
differently. If you used to pass the data for processing to
functions you shall pass not “response” but “response.data”, and
watch for “response.paging”, to see if there are more friends to add
by additional calls.
Related
I am trying to use the Twitter API to tweet, retweet, and upload images, while tweet works as intended, upload media don't work. more information below
packages i use :
node-fetch
deepmerge - to merge the given options
oauth-1.0a
crypto
the error appears at all the fetch request related to this function
Error:
{ errors: [ { code: 32, message: 'Could not authenticate you.' } ] }
I know whats the error is about, just asking this as I am confused why this would appear only in this function,as the auth info is correct and the same function used to create the headers work in another function
some important functions and related : https://hastebin.com/eyepikidax.kotlin
the code affected : https://hastebin.com/inehomodag.js
tweet function : (the working function) : https://hastebin.com/xatebakahe.properties
even though the tweet works with the same function _makeRequest(custom function) uploadmedia dont
uploadmedia is same as tweet but with extra steps like uploading media
i logged the headers provided by _makeRequest for the tweet function and the upload function
headers: https://hastebin.com/xojotupine.rust
it seems in the uploadmedia function the headers became invalid but in the tweet function they are valid
The issue was with the authorization headers, I had to generate them for each request.It was easy as creating a wrapper function that will take the request details (the needed ones) and output the headers
I have a Twitter API library written in typescript (unmaintained for now :/ )
That uses this, don't suggest completely using that, just take what you need from it
Code Related
^^
Above Links to - https://github.com/typicalninja493/tweets.ts/blob/master/src/rest/bucket.ts#L200
I'm trying to add a Payment Request Button to my Ionic 5 app. However, no matter how I run the app, I always get the following message and the button won't show.
[warn] - You may test your Stripe.js integration over HTTP. However,
live Stripe.js integrations must use HTTPS.
I'm loading the Stripe API over https
<script src="https://js.stripe.com/v3/"></script>
I've imported it in to my page
declare var Stripe;
// Check the availability of the Payment Request API first.
const prButton = elements.create('paymentRequestButton', {
paymentRequest,
});
paymentRequest.canMakePayment().then(result => {
if (result) {
prButton.mount('#payment-request-button');
} else {
document.getElementById('payment-request-button').style.display = 'none';
}
);
I've tried running it in Safari on Mac (running with --ssl and a valid certificate), Xcode Emulator, A Real iPhone and the result is always the same.
Also worth noting is that I'm using Capacitor, not Cordova. I've tried this in my capacitor.config.json but it had no effect.
"iosScheme": "https",
Update:
So it turns out that it's because the app runs with the local urlScheme of capacitor:// rather than https:// and the development team at Ionic currently have no plans to rectify this. Is there any way to make the Payment Request Button appear in a non-https environment?
After a lot of back and forth with Stripe's support team, I finally came up with a solution. A lot of what they said is included in this answer (placed in blockquotes). I've also included a code example that will hopefully help make sense of it.
I'm absolutely aware this is quite complex but unfortunately when not
using our official iOS SDK the process is quite involved, and as of
right now we don't have any official support for cross-platform
technologies like Ionic or React Native.
You must have an apple developer account, a merchant id and have a payment processing certificate uploaded to stripe (see steps 1->3 of https://stripe.com/docs/apple-pay#native)
You can use the cordova plugin (https://github.com/samkelleher/cordova-plugin-applepay#example-response) to generate an apple pay token. This will then be submitted to the V1 stripe API and exchanged for a Stripe Token. This is how Stripe's official IOS SDK works by tokenizing the PKPayment object in to a Stripe Token.
The paramaters to pass to the end point (not in the documentation) are;
pk_token (the string that you get from base64 decoding the
paymentData)
pk_token_payment_netowrk (paymentMethodNetwork)
pk_token_instrument_name (paymentMethodDisplayName)
pk_token_transaction_id (transactionIdentifier)
The names in the brackets are what is returned when using the cordova plugin.
Once you call this endpoint, you should get back a standard Stripe
token object(but the request will fail if you haven't registered your
Apple Pay payment processing cert as mentioned above). The Stripe
token(tok_xxx) can be used for payments as normal — the easiest way is
to convert it to a PaymentMethod by calling /v1/payment_methods with
type=card&card[token]=tok_xxxx , and then using it to confirm a
PaymentIntent.
Code Example
completeApplePay(resp){
const _this = this;
return new Promise((resolution, rejection) => {
$.post({
url: 'https://api.stripe.com/v1/tokens',
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Bearer pk_test_xxxxxxxxxxxxxxxx")
},
data: {
pk_token: atob(resp.paymentData),
pk_token_payment_network: resp.paymentMethodNetwork,
pk_token_instrument_name: resp.paymentMethodDisplayName,
pk_token_transaction_id: resp.transactionIdentifier
},
success: function (data) {
resolution({
token: data.id
});
}
});
});
}
The (resp) parameter in the function above is the response from the cordova plugin;
const applePayTransaction = await this.applePayController.makePaymentRequest(order).then(resp => {
this.stripe.completeApplePay(resp).then((stresp:any) => {
// code goes here to store order in database etc
})
});
await this.applePayController.completeLastTransaction('success');
I'm trying to fetch featured image from my published post but it seems impossible! I get
an error :( that's the code:
function fetchSlideShow(){
let endpoint = "http://loreleiheckmann.com/wordpress/wordpress/wp-json/wp/v2/Vinyls?_embed";
fetch(endpoint)
.then(e => e.json())
.then(showSlideShow);
}
function showSlideShow(data){
console.log(data);
data.forEach(showSingleSlide);
showSlides();
}
function showSingleSlide(aSlide) {
let template = document.querySelector(".slide_template").content;
let clone = template.cloneNode(true);
console.log(aSlide);
clone.querySelector("img").setAttribute("src", aSlide._embedded["wp:featuredmedia"]
[0].media_details.source_url);
let SlideList = document.querySelector("#SlideList");
SlideList.appendChild(clone);
}
While going to the array I see error 401 :( and moreover: Cannot read property 'source_url' of undefined" I don't know what I'm doing wrong .. any insights?
HERE ARE THE ERRORS -> 401 ON CONSOLE + PROBLEM WITH URL.:
Please try changing your url in the endpoint variable:
let endpoint = "http://loreleiheckmann.com/wordpress/wordpress/wp-json/wp/v2/posts?per_page=20&_embed=wp:featuredmedia
If you need more data you can add them with a comma:
wp-json/wp/v2/posts?per_page=20&_embed=wp:term,wp:featuredmedia
Post per page is optional, but I would prefer having that set.
And you should write what image size you need. That way rest api will give you the right source url:
_embedded['wp:featuredmedia']['0'].media_details.sizes.medium_large.source_url
I think it would also be better practice if you use an ssl certificate, there are free by "Let's encrypt".
EDIT:
Your screenshot shows the rest api message:
wp:featuredmedia: Array(1)
0:
code: "rest_forbidden"
data: {status: 401}
message: "Sorry, you are not allowed to do that."
So the 401 status code means: unauthorised
Seems like you are not allowed to access the data via rest api.
There could be multiple reasons for that:
The image is attached to an unpublished post. The post may have the status "private" or "draft", and therefore is not public available.
Your post (and attached image) is not available for not logged in users. If there is a restriction to view your code, this also applies to rest api.
Maybe you are using some kind of membership plugin that restricts the wp rest-api. Try deactivating all plugins if one of them affects the behaviour.
You have added some custom code to restrict access rest api access.
If nothing works for you, you should look into your database and check the medias post_status.
I think it is working fine, but you do not have access to view the posts data. This is what the 401 error indicates.
To whom it may concern - In the end, I added image in WP by custom post type ( I gave up wp:featured media - I wasn't able to fetch it.) Afterward I added a code to JS -> b.querySelector(".img").setAttribute("src", a.acf.image.url); so it works:)
So I did a tutorial on Soundcloud SDK through CodeAcademy here and wanted to take the knowledge I learned from that and put it on Codepen. But I want to use a different track than the one they use in this tutorial - specifically this song https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download.
I read that /resolve was a good approach to get the trackid but it's not working. I get 403 Forbidden in the console.
SC.get('/resolve/?url=https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download&client_id=3596a42d6242b9c1ee76740a7771d33a', function(track) {
console.log(track); // returns null
});
Here is my codepen. Please help me load this track for my basic SoundCloud SDK audio player. Thanks
Your code is correct and even works with some tracks, for example the ones from the documentation.
You're encountering a problem that I found personally should be emphasized in their documentation. The API access for this track has been disabled (even if the widget is enabled), therefore your have not right to query this track using the API and it returns a 403 Forbidden HTTP status code.
This is described in the Linked Services part of the SoundCloud terms of use:
You can limit and restrict the availability of certain of Your Content to other users of the Platform, and to users of Linked Services, at any time using the permissions tab in the track edit section for each sound you upload, subject to the provisions of the Disclaimer section below.
You can check in your code if any error like this one was encountered while fetching the track informations and depending on the success or failure, continue with the correct action:
var clientId = 'CLIENT_ID';
SC.initialize({
client_id: clientId
});
var songUrl = 'https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download';
SC.get('/resolve?url=' + songUrl + '&client_id=' + clientId, function(data, error) {
if (error === null) {
console.log('Do something like playing the song.');
} else {
console.log('Print an error message?');
}
});
I'm building Firefox addon (with addon-SDK) and I'd like to display desktop notification to a user.
There is Notification object but it doesn't seem to work from addon code (background page). There is no error etc, but no dialog for permissions is displayed, so no notifications can be displayed. I've tried of course adding permissions/desktop-notifications but no effect.
Edit: pasting sample code I've tried (the code is located inside callback function for socket.io event. Event is received properly, but no notification is displayed, or request for permission.
Notification.requestPermission( function(status) {
console.log(status); // notifications will only be displayed if "granted"
var n = new Notification("title", {body: "notification body"}); // this also shows the notification
});
I've also found alerts service this one works. However alerts disappear quite fast (too fast for me) - edit: that's the way it works - so guess no code sample needed, as I don't see any option to make them last longer.
Is there any way to display chrome like notifications on Firefox? (chrome.notifications.create) Or at least use web notifications object from within the addon?
If you're using the add-on SDK, you're looking at the wrong docs. Here are the notification docs.
You create a notification like so:
var notifications = require("sdk/notifications");
notifications.notify({
title: "Jabberwocky",
text: "'Twas brillig, and the slithy toves",
data: "did gyre and gimble in the wabe",
onClick: function (data) {
console.log(data);
}
});
All the docs you look at should be a subset of developer.mozilla.org/en-US/Add-ons/SDK.