So I hope someone call help me with this issue as I'm not too sure if its javascript, or if its facebook.
Here's my situation. I upgraded to Requests 2.0 on facebook, which no longer gives me the ability to add an exclude_ids field to the form where users will invite their friends to the App. The purpose of this form is not to just invite friends, but to add friends as something in the App.
In short, I have a list of friends that they have already added, and I want to filter that from the master list of their friends so that when they want to use the form, the friends already added do not show up.
Here is my javascript to get the friends:
<script language="Javascript" type="text/javascript">
var friends_filter = '<?=$myClass->getFiltered());?>';
</script>
Will return something like:
999999999,999999999,999999999,999999999,999999999,999999999,999999999
Which is a list of IDs of the users who they have NOT added that are their friends.
Here is my code for the form:
function addUser() {
FB.ui(
{
method: 'apprequests',
display: 'dialog',
title: 'Add friends',
message: 'Hey, I added you as a user/friend on such-and-such App',
data: 'added',
filters: [{name: 'Non-Added', user_ids: [friends_filter]}],
},
function(response) {
if(response && response.request_ids) {
showLoading('Adding Relatives');
var dataString = 'rids='+response.request_ids;
$.ajax({
type: "GET",
url: server_url+"ajax/add_relative.php",
data: dataString,
success: function(data){
window.location.reload();
}
});
}
}
);
}
If you look at the filters: [{name: 'Non-Added', user_ids: [friends_filter]}], line, that is where I include the list of IDS that I only want to see in the selector. The dialog pops up, but then list those ID's in friends_filter and an error message stating "does not resolve to a valid user ID"
This is where I get confused, if I copy and paste what friends_filter outputs and replace it the friends_filter with the list of IDs, i.e. 999999999,999999999,999999999,999999999, exactly as it appears, it works correctly.
I know this is an exhaustive post and I'm sorry, but I'm at my wits end.
The only thing I could think of is that perhaps my javascript variable friends_filter needs to be converted to some type of some sort?
Any ideas?
i was try this code and it is work good with me
FB.ui(
{
method: 'apprequests',
filters: ['app_non_users'],
message: 'msg here!',
title: 'title for box'
},
function(response) {
alert(response.request_ids);//this is return after send invite
}
);
just if you want filter result with list of user use
filters: [{name: 'Invite friends', user_ids: <?php echo json_encode($users_array);?> }],
After much trial and error, I figured out the solution.
in:
<script language="Javascript" type="text/javascript">
var friends_filter = '<?=$myClass->getFiltered());?>';
</script>
I changed to
<script language="Javascript" type="text/javascript">
var friends_filter = [<?=$myClass->getFiltered());?>];
</script>
By replacing the quotes around the php echo with brackets.
Then I changed:
filters: [{name: 'Non-Added', user_ids: [friends_filter]}],
To:
filters: [{name: 'Non-Added', user_ids: friends_filter}],
If you want to exclude those (of your friends) who added the application, you simply use:
filters: ['app_non_users']
Related
I want to respond to an inline query but there is no response from my bot. However, Telegram returns {"ok":true,"result":true} as the HTTP response. Here's my Google Apps Script code:
var execute = "https://api.telegram.org/bot" + token + "/";
function answerInlineQuery(id,text){
var output = {
method: "post",
payload: {
method: "answerInlineQuery",
inline_query_id: id,
result: [{
type: "article",
id: id,
title: "This is a title",
description: text,
input_message_content: {
message_text: text,
},
}]
}
};
UrlFetchApp.fetch(execute,output);
}
How do I solve this? Is there something wrong with my code? Or is there something to do with the bot settings (BotFather)?
In case you need a demonstration of the problem, try the bot yourself by using an inline query (type #ClearTheBot [something] in any chat).
https://t.me/ClearTheBot
Please kindly change output.payload.results[0].id to 1 and/or JSON.stringify(output.payload.result)
I have a list of users and checkboxes, I need to get the id's of each check box:checked as well as a subject field and a message field and pass to my controller. The only way I could think to do this was to grab each id and duplicate the subject and message fields and pass to a multidimensional array to my controller. My array looks like this:
[{id: "46", subject: "sample subject1", message: "test message1"}{id: "46", subject: "sample subject1", message: "test message1"}]
This seems really redundant as I only need the list of user ids and 1 copy of the message and subject fields in the array but not sure if there is a better way to do this or not. Is it possible to send two different arrays via ajax to my codeigniter controller? If so how do I access them in the controller?
Here is an example of my code to collect ids and create the array. If this is the best method I am still not sure how to handle a multidimensional array in my controller. Normally I would access the array contents using $this->input->post('key') but, that wont work: I think I would need to loop through the array first in the controller but not sure how to do.
Here is my code:
$(document).on('click', '.send_btn', function(e) {
//get ids of selected users
var subject = 'test subject';
var message = 'test message';
var data = [];
$(':checkbox[name="people_checked[]"]:checked').each (function () {
data.push({
id: this.id,
subject: subject,
message: message
})
});
$.ajax({
url: "/message/send_message",
method: "POST",
success: function (data) {
console.log('Success');
}
})
});
Any help advice is much appreciated.
If you want to DRY up the array, convert it to an object which has the subject and message properties in the root. Then you can provide the ids property as an array. It would look something like this:
$(document).on('click', '.send_btn', function(e) {
var data = {
subject: 'test subject',
message: 'test message',
ids: $(':checkbox[name="people_checked[]"]:checked').map((i, el) => el.id).get()
};
$.ajax({
url: "/message/send_message",
method: "POST",
data: data, // note this was added, you didn't send a body in the original
success: function(data) {
console.log('Success');
}
})
});
The output would be:
{
subject: 'test subject',
message: 'test message',
ids: [ 123, 987 ]
}
You would obviously need to amend your /message/send_message endpoint to work with a request body in that format.
I'm using bootstrap-table with inline editable plugin to create a bootstrap table for a list of laptop. My goal was to apply changes to my csv file after users make changes to the table like this example (Product Category: Laptop)
I have created a javascript function below to send Ajax data to my Django server.
// ajax to server
$(function () {
$( "#table" ).on("click" , 'button',function(event){
var selected_item = getSelectedRow(); //this will return selected row object
console.log(selected_item);
$.ajax({
type: "post",
url: '/update/',
data: {
'item': JSON.stringify(selected_item)
},
success: function (data) {
alert('success');
}
});
});
});
Below is the output from my console log
(pcategory has been changed to Laptop2)
However, when I try to get the data from Django. It gave me the output below, which (pcategory was not changed to Laptop2)
{'webcam': 'WebCam', 'lannum': '2', 'condition': 'Refurbished', 'video2': 'GM204M [GeForce GTX 970M]', 'memorybanks': '8G 2133MHz/8G 2133MHz/', 'cpus': '1', 'customernotes': '', 'lanmodels': 'Killer E2400 Gigabit Ethernet Controller/WLAN QCA6174 802.11ac Wireless Network Adapter/', 'internalnotes': '', 'pline': 'Alienware', 'sku': 'LEN-LT-TPEdge-03BV001', 'cddvd': '', 'hddcapacity': '0.0G', 'coresthreads': '4 | 8', 'sound': 'Sound-Yes', 'pmodel': '15 R2', 'resolution': '1230x1000', 'ptype': 'Minitower', 'grade': 'GradeB:R2-Ready for Resale', 'touchscreen': 'Yes', 'hddqty': '0', 'pcategory': 'Laptop', 'processor': 'i7-6700HQ 2.60GHz', 'memory': '16G', 'serialnum': 'BFYNM72', 'video1': 'GM204M [GeForce GTX 970M]', 'hddmodels': '', 'manufacturer': 'Alienware', 'motherboard': 'Alienware 15 R2', 'batch': '03BV', 'hddserialnum': ''}
My Django view function:
#csrf_exempt
def update_page(request):
file_path = os.path.join(CSV_BASE_DIR, CURRENT_BATCH, '{}.csv'.format(CURRENT_BATCH))
if request.method == 'POST':
item = json.loads(request.POST.get('item'))
pprint.pprint(item)
overwrite_csv(file_path,item)
else:
print('no data back!')
return HttpResponse('yes')
I noticed when I changed the input again. The value will get changed to laptop2. It seems like it didn't save the value in the way I expect it to be. I'm wondering is there any way my Django server would get the same value as soon as I click on the check mark?
Thank you all in advanced.
Make sure the data source is Same for both listing and updating.
I'm using Select2 (http://ivaynberg.github.io/select2/) to have an input field of a form (let's say its id is topics) to be in tagging mode, with the list of existing tags (allowing the user to choose some of these tags, or to create new ones) being provided by an array of remote data.
The array (list.json) is correctly got from my server. It has id and text fields, since Select2 seems to need these fields. It thus looks like this:
[ { id: 'tag1', text: 'tag1' }, { id: 'tag2', text: 'tag2' }, { id: 'tag3', text: 'tag3' } ]
The script in the HTML file looks like this:
$("#topics").select2({
ajax: {
url: "/mypath/list.json",
dataType: 'json',
results: function (data, page) {
return {results: data};
},
}
});
But the input field is showing "searching", which means it's not able to use the array for tagging support.
In the script with Select2, I know I have to define formatSelection and formatInput, but I'm not getting how they should work in my case, although I have read the Select2 documentation... Thank you for your help!
You need to add the function like explained here. In your example:
function format(state) {
return state.text;
}
I've setup a stripe custom checkout using javascript. Every parameter goes through, I receive a status 200 in the log when we make a payment. Everything looks like it goes through. However the amount remains as "0" in the Parsed Request Query Parameters and not charging the card.
I've gone over documentation for hours and can't get my head around the issue.
<script src="https://checkout.stripe.com/checkout.js"></script>
<script>
var pinId = "<%= #id %>";
var from = "<%= #from %>";
var content = "Supersize+me";
var handler = StripeCheckout.configure({
key: 'Published-Key',
image: '/assets/campusboard-logo.png',
token: function(token, args) {
$.getJSON( "purchased/"+pinId )
.done(function( data ) {
window.location = "http://"+window.location.host+"/pins/"+pinId+"?utm_source=Purchased&utm_medium="+from+"&utm_campaign=Featured%20Pins&utm_content="+content;
})
.fail(function( jqxhr, textStatus, error ) {
alert("We've encountered a problem with the transaction. Please try again.");
});
}
});
document.getElementById('ssm').addEventListener('click', function(e) {
// Open Checkout with further options
handler.open({
name: 'CampusBoard',
description: 'Featured Pin (£29.00)',
amount: "100",
currency: 'GBP',
panelLabel: 'Supersize my Pin'
});
e.preventDefault();
});
document.getElementById('mmh').addEventListener('click', function(e) {
// Open Checkout with further options
handler.open({
name: 'CampusBoard',
description: 'Featured Pin (£59.00)',
amount: 5900,
currency: 'GBP',
panelLabel: 'Make my Pin Huge'
});
content = "Make+me+huge";
e.preventDefault();
});
</script>
Can someone see where I'm going wrong?
Stripe Checkout is just a well-done pre-made payment form. You actually have to create a Charge object on your server using your Stripe secret API key. Follow these tutorials for your specific language.
You are passing the amount as a string whereas I think stripe is expecting it as a number. So:
handler.open({
...
amount: 100,
...
});